基本上,我使用AJAX调用了这个840个JSON对象数据集,并使用div和简单的Bootstrap分页进行显示。现在我的问题是,我有94页,所有页面按钮都一直显示。我认为这既不实用、美观也不用户友好,所以我想要解决这个问题。
所以我在互联网上搜索了这个问题。我找到了几个分页插件,像simplePagination.js或twbsPagination,它们应该能够提供我需要的功能。后者对我来说效果最好,但仍然无法正确运行。我能够启动新的分页,但它不能更改实际页面内容。我现在尝试了许多更多的插件并尝试修改我的现有代码,但没有任何作用。我现在已经将我的代码恢复到正常的分页状态。
所以我在互联网上搜索了这个问题。我找到了几个分页插件,像simplePagination.js或twbsPagination,它们应该能够提供我需要的功能。后者对我来说效果最好,但仍然无法正确运行。我能够启动新的分页,但它不能更改实际页面内容。我现在尝试了许多更多的插件并尝试修改我的现有代码,但没有任何作用。我现在已经将我的代码恢复到正常的分页状态。
pageSize = 9;
var pageCount = $(".line-content").length / pageSize
//calculating the number of pages needed
var pagin = document.getElementById('pagin');
//deleting the previous displayed page buttons
while (pagin.firstChild) {
pagin.removeChild(pagin.firstChild);
}
for (var i = 0; i < pageCount; i++) {
//creating the page items
$("#pagin").append('<li class="page-item"><a class="page-link" href="#">' + (i + 1) + '</a></li> ');
}
//styling the current page item
$("#pagin li").first().find("a").addClass("current")
// the function to actually change the content on the selected page
showPage = function (page) {
$(".line-content").hide();
$(".line-content").each(function (n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1); //displaying the content
//changing the style
$("#pagin li a").click(function () {
$("#pagin li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
基本上我已经实现了分页,但是我希望它更加漂亮。我可以尝试使用任何jquery插件等来达到这个效果,只要它能满足我的期望。 我的分页看起来像这样 我希望它看起来像这样