gpt4 book ai didi

javascript - 使用下一个和上一个按钮分页,使用 jQuery 在 HTML 表格中加载时仅显示 5 页

转载 作者:太空宇宙 更新时间:2023-11-04 07:58:18 25 4
gpt4 key购买 nike

我没有。页数,但我想通过使用下一页和上一页按钮显示加载的 5 页来限制它 which shows pages number .

我的代码是:

  <script>
$(document).ready(function() {
var totalRows = $('#MyTable').find('tbody tr:has(td)').length;
var recordPerPage = 10;
var totalPages = Math.ceil(totalRows / recordPerPage);
var $pages = $('<div id="pages"></div>');
var $previous = $('<span class="previous"><<</spnan>');
var $next = $('<span class="next">>></spnan>');
for (i = 0; i < totalPages; i++) {
$('<span>' + (i + 1) + '</span>').appendTo($pages);
}
$pages.appendTo('#MyTable');

$('#MyTable').find('tbody tr:has(td)').hide();
var tr = $('#MyTable tbody tr:has(td)');
for (var i = 0; i <= recordPerPage-1; i++) {
$(tr[i]).show();
}
$('span').click(function(event) {
$('#MyTable').find('tbody tr:has(td)').hide();
var nBegin = ($(this).text() - 1) * recordPerPage;
var nEnd = $(this).text() * recordPerPage - 1;
for (var i = nBegin; i <= nEnd; i++)
{
$(tr[i]).show();
}
});
});
</script>

我的分页如下: “第一个 上一个 1 2 3 4 5 下一个 最后一个”

希望你们明白?

提前致谢。

最佳答案

Hi, You can create simple pagination using the TWBS pagination JS library. here is a quick example of pagination on codepen it might help you.

example code on codepen

https://codepen.io/SitePoint/pen/WprNwa/

关于javascript - 使用下一个和上一个按钮分页,使用 jQuery 在 HTML 表格中加载时仅显示 5 页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47175845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com