Pagination in jsp using jQuery is not working

2019-09-20 14:31发布

jQuery(function($){ var items = $("table tr"); var numItems = items.length; var perPage = 2; items.slice(perPage).hide(); $(".pagination-page").pagination({ items: numItems, itemsOnPage: perPage, cssStyle: "light-theme", onPageClick: function(pageNumber) { var showFrom = perPage * (pageNumber - 1);var showTo = showFrom + perPage; items.hide(); .slice(showFrom, showTo).show();}});

1条回答
Summer. ? 凉城
2楼-- · 2019-09-20 14:57

You have a number of syntax errors in your example. Assuming that your html table is populated correctly on the server-side, this seems to work fine:

$(function($) {
  var items = $("table tr");
  var numItems = items.length;
  var perPage = 2;
  items.slice(perPage).hide();
  $(".pagination-page").pagination({
    items: numItems,
    itemsOnPage: perPage,
    cssStyle: "light-theme",
    onPageClick: function(pageNumber) {
      var showFrom = perPage * (pageNumber - 1);
      var showTo = showFrom + perPage;
      items.hide();
      items.slice(showFrom, showTo).show();
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ciiing-project-learn.googlecode.com/svn-history/r1792/trunk/projects/eddie/app/webroot/js/jquery.simplePagination.js"></script>

<table>
  <tr><td>1</td></tr>
  <tr><td>2</td></tr>
  <tr><td>3</td></tr>
  <tr><td>4</td></tr>
  <tr><td>5</td></tr>
  <tr><td>6</td></tr>
  <tr><td>7</td></tr>
  <tr><td>8</td></tr>
  <tr><td>9</td></tr>
  <tr><td>10</td></tr>
</table>

<div class="pagination-page"></div>

查看更多
登录 后发表回答