前端分页按钮算法
算法一:
var begin; var end; //总共显示10个页码 if(totalPage<10){ begin=1; end=totalPage; } else{ begin=currentPage-5; end=currentPage+4; if(begin<1){ begin=1; end=begin+9; } if(end>totalPage){ end=totalPage; begin=end-9; } } for(var i=begin;i<=end;i++){ //生成页码 }
算法二:
//显示五个按钮 var pageStart=pageIndex-2>0?pageIndex-2:1; var pageEnd=pageIndex+2>pageCount?pageCount:pageStart+4; for(var i=pageStart;i<=pageEnd;i++){ //生成页码 }