JS分页
作者:互联网
//当前页数 var currentPage;
//首页点击事件 $("#homePage").click(function() { if(currentPage!=1){ goPage(1); currentPage=1; } }); //尾页点击事件 $("#endPage").click(function() { if(currentPage!=totalPage){ goPage(totalPage); currentPage=totalPage; } }); //上一页页点击事件 $("#pageUp").click(function() { if(currentPage>1){ goPage(currentPage-1); currentPage-1; } }); //下一页点击事件 $("#pageDown").click(function() { if(currentPage<totalPage){ goPage(currentPage+1); currentPage+1; } });
/** * 分页函数 **/ function goPage(pno){ var itable = $("#history").find("li"); var num = itable.length;//表格所有行数(所有记录数) //console.log(num); //每页显示行数 var pageSize = 10; //总共分几页 if(num/pageSize > parseInt(num/pageSize)){ totalPage=parseInt(num/pageSize)+1; }else{ totalPage=parseInt(num/pageSize); } //当前页数 currentPage = pno; //开始显示的行 var startRow = (currentPage - 1) * pageSize+1; //结束显示的行 var endRow = currentPage * pageSize; endRow = (endRow > num)? num : endRow; //console.log(endRow); //遍历显示数据实现分页 for(var i=1;i<(num+1);i++){ var irow = itable[i-1]; if(i>=startRow && i<=endRow){ irow.style.display = "block"; }else{ irow.style.display = "none"; } } $("#pages").html("第"+currentPage+"/"+totalPage+"页"); }
标签:function,分页,pageSize,JS,num,var,currentPage,endRow 来源: https://blog.csdn.net/wow357591543/article/details/97630135