算法一:算法
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++){ //生成頁碼 }
算法二:spa
//顯示五個按鈕 var pageStart=pageIndex-2>0?pageIndex-2:1; var pageEnd=pageIndex+2>pageCount?pageCount:pageStart+4; for(var i=pageStart;i<=pageEnd;i++){ //生成頁碼 }