开发者

Mootools: Dynamically creating pagination links

开发者 https://www.devze.com 2022-12-16 04:08 出处:网络
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 oncl

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

精彩评论

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