【发布时间】:2019-09-29 16:18:59
【问题描述】:
所以基本上我使用 AJAX 调用这个 840 Json 对象数据集,并使用 div 和足够简单的引导分页显示它。现在我的问题是,我有 94 个页面,并且所有页面按钮都一直显示。我认为这既不实用、不美观也不对用户友好,所以我想解决这个问题。
所以我已经在互联网上搜索了这个问题。我发现了几个分页插件应该可以提供我需要的东西,比如 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 插件和一切都持开放态度。只要它做我希望它做的事。 My pagination looks like this I'd like to have it looking somewhat like this
【问题讨论】:
标签: javascript jquery html ajax bootstrap-4