js分页代码

pageNo(total,currentPage,perPage,showIndex)
功能:根据当前页码获取当前分页索引号  
参数说明:total:总记录条数,currentPage:当前页码,perpage:一页显示多少条记录,showIndex:前后拓展几页goToPage(whichPageToGo,recordsPerPage,totalRecordNumber,expandHowMany,currentRedPage,totalPages)<br>功能:跳到指定的索引页<br>参数说明:要跳到的页码,每页显示多少记录条数,总记录条数,拓展几页,当前页码(红色标志),总页数<br>注意:调用顺序:pageNo()先调用,之后才能调用goToPage()。因为pageNo计算出总页数<br>_currentPage=2;设置当前页码<br>_indexContainer=document.all.splitpage;设置存放分页索引号的容器<br>_contentContainer=document.all.contents;设置存放分页内容的容器<br>_totalPages=0;初始化总页数<br>(function pageLoad(){<br>_indexContainer.innerHTML=pageNo(102,_currentPage,10,5).join(” ”);<br>goToPage(_currentPage,10,102,5,_currentPage,_totalPages)<br>})()<br>function pageNo(total,currentPage,perPage,showIndex){<br>var showIndex=showIndex?showIndex:5;<br>var currentPage=currentPage?currentPage:1;<br>var perPage=perPage?perPage:5;<br> if(total/perPage>parseInt(total/perPage)){<br>  pages=parseInt(total/perPage) 1;<br> }<br> else{<br> pages=parseInt(total/perPage);<br> }<br> if(pages==1){return ””;}<br> _totalPages=pages;<br>var pageIndex=[];<br>pageIndex.push(”<font style='cursor:hand' οnclick=goToPage(_currentPage-1,” perPage ”,” total ”,” showIndex ”,” currentPage ”,” pages ”)>上一页</font>”);<br>if(pages<=2*showIndex)<br> {<br>  for(var i=1;i<=pages;i  )<br>  {<br>   if(i==currentPage){<br>   pageIndex.push(”<font style='cursor:hand' color=red οnclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br>   }<br>   else{<br>   pageIndex.push(”<font style='cursor:hand' οnclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br>   }<br>  }<br> <br> }<br>else{<br>if((currentPage-showIndex)<1)<br>{var startIndex=1;}<br>else<br>{var startIndex=currentPage-showIndex;}<br>if((currentPage showIndex-1)>pages)<br>{var endIndex=pages;}<br>else<br>{var endIndex=(currentPage showIndex-1);}<br>  for(var i=startIndex;i<=endIndex;i  )<br>  {<br>   if(i==currentPage){<br>   pageIndex.push(”<font style='cursor:hand' color=red οnclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br>   }<br>   else{<br>   pageIndex.push(”<font style='cursor:hand' οnclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br>   }<br>  }<br>  <br> }<br> pageIndex[pageIndex.length]=”<font style='cursor:hand' οnclick=goToPage(_currentPage 1,” perPage ”,” total ”,” showIndex ”,” currentPage ”,” pages ”)>下一页</font>”<br> return pageIndex;<br>}<br>function goToPage(index,RecordsPerPage,totalRecords,onceShow,currentPage,total_page){<br>index<1?index=total_page:””;<br>index>total_page?index=1:””;<br>var startIndex=(index-1)*RecordsPerPage;<br>var endIndex=index*RecordsPerPage-1;<br>_currentPage=index;<br>if(endIndex>totalRecords-1){endIndex=totalRecords-1;}<br>_contentContainer.innerHTML=getRecord(startIndex,endIndex);<br>_indexContainer.innerHTML=pageNo(totalRecords,index,RecordsPerPage,onceShow).join(” ”);<br>}<br>function getRecord(startIndex,endIndex){<br>return ”开始记录” startIndex ”这里放取得的记录数据” ”<br>结束记录” endIndex;<br>} 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值