使用jQuery在jsp中的分页不起作用

时间:2015-02-18 06:10:08

标签: javascript jquery html jsp jquery-pagination

jQuery(function($){var items = $(" table tr"); var numItems = items.length; var perPage = 2; items.slice(perPage).hide(); $ (" .pagination-page")。分页({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 个答案:

答案 0 :(得分:0)

您的示例中有许多语法错误。假设您的html表在服务器端正确填充,这似乎工作正常:



$(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>
&#13;
&#13;
&#13;