pageNo(total,currentPage,perPage,showIndex)<br>功能:根据当前页码获取当前分页索引号 <br>参数说明:total:总记录条数,currentPage:当前页码,perpage:一页显示多少条记录,showIndex:前后拓展几页<br>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' onclick=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 onclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br> }<br> else{<br> pageIndex.push(”<font style='cursor:hand' onclick=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 onclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br> }<br> else{<br> pageIndex.push(”<font style='cursor:hand' onclick=goToPage(” i ”,” perPage ”,” total ”,” showIndex ”,” currentPage ”)>” i ”</font>”);<br> }<br> }<br> <br> }<br> pageIndex[pageIndex.length]=”<font style='cursor:hand' onclick=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>}
posted on 2006-07-10 09:36
汪杰 阅读(700)
评论(0) 编辑 收藏 引用 所属分类:
javascript