Pagination with JavaScript

时光总嘲笑我的痴心妄想 提交于 2019-12-12 17:04:39

问题


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)


回答1:


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




回答2:


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");




回答3:


Good jQuery pagination plugin to use with JSON data




回答4:


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.



来源:https://stackoverflow.com/questions/6060775/pagination-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!