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:
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>