开发者

Mootools: Dynamically creating pagination links

I am trying to dynamically create pagination links based on the total number of results returned from a JSON query. I am using a for loop to create a new "a" tag for each page. I want to add an onclick event to each link that passes in loop index to a function that changes the page.

The problem is that the index passed into the function is always the same. For example, if I loop through and create 10 links then the index is always 11. If I loop through and create 3 links the the index is always 4.

I have created a snippet of my class at MooShell that demostrates this. http://mootools.net/shell/SE3bb/

The desried Html should look like this:

<div id="top-pages" class="pagination">
    <a onclick="changePage(1)">1</a>
    <开发者_开发技巧;a onclick="changePage(2)">2</a>
    <a onclick="changePage(3)">3</a>
</div>

<div id="products">Products go here</div>

<div id="bottom-pages" class="pagination">
    <a onclick="changePage(1)">1</a>
    <a onclick="changePage(2)">2</a>
    <a onclick="changePage(3)">3</a>
</div>


http://mootools.net/shell/9sHYa/

fixed using element storage at the time of building which is retrieved at the click function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜