admin管理员组

文章数量:1391947

I have html code that have some <div class="post"> inside. I want to paginate them with javascript. How can I do that? (I know I can do it by PHP but I just want to do it with JS)

the html generated by my php looks like that:

    <body>
<div id="content">
<div class="post">
post content
</div>
<div class="post">
</div>
...

</div>

</body>

Maybe it will be the best to use jquery for that? (I'm using jquery ajax to load html into content allready)

I have html code that have some <div class="post"> inside. I want to paginate them with javascript. How can I do that? (I know I can do it by PHP but I just want to do it with JS)

the html generated by my php looks like that:

    <body>
<div id="content">
<div class="post">
post content
</div>
<div class="post">
</div>
...

</div>

</body>

Maybe it will be the best to use jquery for that? (I'm using jquery ajax to load html into content allready)

Share Improve this question edited May 19, 2011 at 15:10 pixelbobby 4,4405 gold badges31 silver badges50 bronze badges asked May 19, 2011 at 15:07 Adrian ModliszewskiAdrian Modliszewski 1,1242 gold badges19 silver badges31 bronze badges 3
  • 2 Do you mean hiding some of the posts? If you paginate in JS either you will have all the posts loaded or you need AJAX and call the PHP that does the pagination server side – Miquel Commented May 19, 2011 at 15:12
  • The point is that I want to have all post loaded, and only paginate them in javascript – Adrian Modliszewski Commented May 19, 2011 at 15:18
  • 2 Then you could use something like the acordeon or tabs plugins in JQuery using a tab for a "page" of posts for example. flowplayer/tools/demos/tabs/accordion.html – Miquel Commented May 19, 2011 at 15:20
Add a ment  | 

5 Answers 5

Reset to default 1

yea there is a jquery plugin that works nicely https://github./gbirke/jquery_pagination

I would first get the count of items. For example, if you have 10, loop through and create <div>s for each. [1][2][3]... Then, when you click on a pager <div>, get the value and request that specific item such as $("#ct").load("/posts?id=5");

Good jQuery pagination plugin to use with JSON data

Yes, using jQuery to simulate pagination is a valid task. You could easily use the jQuery(selector).hide().slice(start,end).show() pattern to do what you want. Then you have to manage the start and end in your code, but that should be easy enough.

You can use Pagino. It's very easy and simple https://github./pagino/pagino-js

本文标签: jqueryPagination with JavaScriptStack Overflow