码迷,mamicode.com
首页 > Web开发 > 详细

JS分页方法

时间:2017-11-29 11:36:58      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:sele   判断   首页   +=   rds   func   col   记录   size   

index:当前页码;totalNum:接口返回的记录总条数;

 1 function paging(index,totalNum)
 2 {
 3     pageTotal = Math.ceil(totalNum / pagesize);//总的页数
 4     var htmlShow = ‘‘;//页码
 5     var top = index == 1 ? 1 : parseInt(index - 1);
 6     var buttom = index == pageTotal ? pageTotal : parseInt(index + 1);
 7     htmlShow += "<li><a class=‘words wandn‘ href=‘javascript:void(0);‘  onclick=serach(1)>首页</a>";
 8     htmlShow += "<a class=‘words wandn‘ href=‘javascript:void(0);‘  onclick=serach(" + top + ")> <上页</a><span id=‘htmlnum‘></span>";
 9     //判断显示的页码
10     var indexTop = Math.floor((index-1) / 5);
11     var index5 = parseInt(indexTop * 5 + 5) > pageTotal ? pageTotal : parseInt(indexTop * 5 + 5);
12     htmlShow += "<a class=‘words wandn‘ href=‘javascript:void(0);‘ onclick=serach(" + buttom + ")>下页></a>";
13     htmlShow += "<a class=‘words wandn‘ href=‘javascript:void(0);‘ onclick=serach(" + pageTotal + ")>末页</a>";
14     htmlShow += "<span class=‘fy‘>" + index + "/" + pageTotal + "</span><div class=‘zd_page‘>转到&nbsp;&nbsp;<input id=‘btnSelect‘/><div class=‘goout‘ id=‘go‘>GO</div></div></li>";
15     $("#showPage").html(htmlShow);
16     var htmlnum = "";
17     for (var i = parseInt(indexTop*5+1); i < index5+1; i++) {
18         htmlnum += "<a class=‘num wandn‘ href=‘javascript:void(0);‘  onclick=serach(" + i + ")>" + i + "</a>";//展示的数字
19     }
20     $("#htmlnum").html(htmlnum);
21 }

这里第10、11行的5,所产生的效果是每当点击的页码为(5n+1)时,下方的页码开始变动,可以重新设置参数,没必要写死

JS分页方法

标签:sele   判断   首页   +=   rds   func   col   记录   size   

原文地址:http://www.cnblogs.com/yuchenghao/p/7918933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!