你好我在我的浏览器中得到这个错误,该函数正在工作,我只是好奇为什么我得到这个错误,我可以看到它因为它将currentPage值设置为null但我不明白为什么这是一个问题。分页工作正常我只是想知道我是否可以解决这个错误。我是一个菜鸟。
jquery.simplePagination.js:334 Uncaught TypeError: Cannot set property 'currentPage' of null
at init._selectPage (jquery.simplePagination.js:334)
at init.selectPage (jquery.simplePagination.js:66)
at init.$.fn.pagination (jquery.simplePagination.js:389)
at checkFragment (Blog:440)
at HTMLDocument.<anonymous> (Blog:447)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at Function.ready (jquery.min.js:4)
at HTMLDocument.q (jquery.min.js:4)
<script src="~/Scripts/jquery.simplePagination.js"></script>
<script>
// mind the slight change below, personal idea of best practices
jQuery(function ($) {
// consider adding an id to your table,
// just incase a second table ever enters the picture..?
var items = $("article");
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
if (numItems > 2) {
$(".pagination-page").pagination({
items: numItems,
itemsOnPage: perPage,
cssStyle: "light-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();
}
});
}
// EDIT: extra stuff to cover url fragments (i.e. #page-3)
// https://github.com/bilalakil/bin/tree/master/simplepagination/page-fragment
// is more thoroughly commented (to explain the regular expression)
// we'll create a function to check the url fragment and change page
// we're storing this function in a variable so we can reuse it
var checkFragment = function () {
// if there's no hash, make sure we go to page 1
var hash = window.location.hash || "#page-1";
// we'll use regex to check the hash string
hash = hash.match(/^#page-(\d+)$/);
if (hash)
// the selectPage function is described in the documentation
// we've captured the page number in a regex group: (\d+)
$("#pagination").pagination("selectPage", parseInt(hash[1]));
};
// we'll call this function whenever the back/forward is pressed
$(window).bind("popstate", checkFragment);
// and we'll also call it to check right now!
checkFragment();
});
</script>
使用: http://flaviusmatis.github.io/simplePagination.js/
如果有人对foreach pagnation功能有更好的解决方案,请告诉我。