[英]Pagination with next, previous, last, and first button
I'm a beginner in jQuery and I tried to make a pagination with next, previous, first, and last button, but I cannot. 我是jQuery的初学者,我尝试过使用next,previous,first和last按钮进行分页,但我做不到。
This is my code: 这是我的代码:
pageSize = 8;
var pageCount = $(".group").length / pageSize;
for(var i = 0 ; i<pageCount;i++){
$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
}
$("#pagin li").first().find("a").addClass("current")
showPage = function(page) {
$(".group").hide();
$(".group").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1);
$("#pagin li a").click(function() {
$("#pagin li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
It's not very clear what you're looking for, but I'm guessing you want next/previous links in your pagination links. 目前尚不清楚您要查找的内容,但我猜您想在分页链接中使用下一个/上一个链接。
First is very simple - just link to the page with index 0: 首先非常简单-只需链接到索引为0的页面即可:
$("#pagin").append('<li><a href="#" class="hidden" data-index="0">first</a></li>');
likewise last is just a link to the page count: 同样,最后一个只是指向页面数的链接:
$("#pagin").append('<li><a href="#" class="hidden" data-index="'+pageCount+'">last</a></li>');
prev/next pages will need you to store what the current page is: 上一页/下一页需要您存储当前页面是什么:
https://jsfiddle.net/cfqx3ba6/ https://jsfiddle.net/cfqx3ba6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.