简体   繁体   English

无法使simplePagination jQuery插件正常工作

[英]Can't get simplePagination jquery plugin to work

I have followed instruction of author's page: http://flaviusmatis.github.io/simplePagination.js/ 我遵循作者页面的指示: http : //flaviusmatis.github.io/simplePagination.js/

and from this: How to use SimplePagination jquery . 并由此: 如何使用SimplePagination jquery

And i tried to implement it on my php code as below steps. 我试图按照以下步骤在我的php代码上实现它。 I tried with firebugs but there is no error. 我尝试过萤火虫,但没有错误。 According to the settings of js: it should displayed 5 pages and 2 results in each page. 根据js的设置:应该显示5页,每页显示2个结果。 But it still displayed 10 results as normal and the pagination part only displayed this and unclickable. 但是它仍然正常显示10个结果,并且分页部分仅显示该结果且不可点击。 分页

  1. I have included both css and js file to the header 我已经在标题中包含了css和js文件
  2. My HTML which displays results from database using while loop and there is 10 results. 我的HTML使用while循环显示数据库的结果,有10个结果。

      while ($row = $result->fetch_assoc() { echo "<div id='item'> <div class='title'>$row[title]</div> <div class='description'>$row[description]</div> </div>"; } 
  3. This is div which contains pagination and pagination initializer: 这是div,其中包含分页和分页初始化程序:

      <div class='pagination-page'></div> <script> jQuery(function($) { var items = $("#item"); var numItems = items.length; var perPage = 2; // only show the first 2 (or "first per_page") items initially items.slice(perPage).hide(); // now setup your pagination // you need that .pagination-page div before/after your table $(".pagination-page").pagination({ items: numItems, itemsOnPage: perPage, cssStyle: "compact-theme", onPageClick: function(pageNumber) { // this is where the magic happens // someone changed page, lets hide/show trs appropriately var showFrom = perPage * (pageNumber - 1); var showTo = showFrom + perPage; items.hide() // first hide everything, then show for the new page .slice(showFrom, showTo).show(); } }); }); </script> 

You should not use div id='item' since it produces multiple elements with the same id. 您不应该使用div id ='item',因为它会产生多个具有相同id的元素。 It is very wrong, use class instead. 这是非常错误的,改用类。 Id must be unique. ID必须是唯一的。 It should be sth like this... 应该是这样……

 var items = $(".item"); 
 <div class='item' ... 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM