<div class="codetitle"> <span><a style="CURSOR: pointer" data="19581" class="copybut" id="copybut19581" onclick="doCopy('code19581')"><u>复制代</u></a></span>代码如下:</div> <div class="codebody" id="code19581"> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <BR><html xmlns="http://www.w3.org/1999/xhtml"> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <br><title>JS分页</title> <br><style type="text/css"> <br>body{font-size:12px;} <br>#pager{ height:20px; float:left;} <br>#pager a{height:18px;行の高さ:18px;ボーダー:1px ソリッド #ccc;パディング左:0.4em;パディング右:0.4em;テキスト装飾:なし;表示:ブロック;フロート:左; margin:0px 3px;} <br>#pager a:hover{background-color:#1f3a87;色:#fff; text-decoration:none;} <br>.not-current{background-color:#fff; color:#1f3a87;} <br>.current{背景色:#1f3a87;色:#fff; text-decoration:none;} <br></style> <br></head> <br><body onload="CreatePager(10,10,2043,'?page=14',10)"> <br><script type="text/javascript"> <br>//pageSize,每页显表示何条记录,currentPage当前页,recordCount共有何条记录,url页面路径,必須须带有ページパラメータ,numCount,每页显表示何分页数 <br>var CreatePager=function (pageSize,currentPage,recordCount,url,numCount){ <br>//创建一链接 <br>var CreateHref=function(url,page,p_ele,t,currentPage){ <br>var a=document.createElement(' a'); <br>var reg=new RegExp("page=\d "); <br>url=url.replace(reg.exec(url),'page=' ページ) <br>a.setAttribute('href',url); <br>a.setAttribute('class',currentPage==page?'current':'not-current'); <br>var t=document.createTextNode(t); <br>a.appendChild(t); <br>document.getElementById(p_ele).appendChild(a); <br>} <br>//哪区间に属する計算 <br>var GetNumArea=function(num,numCount,pageCount){ <br>var currentArea=parseInt((num-1)/numCount) 1; <br>var lastArea=parseInt((pageCount-1)/numCount) 1; <br>this.minNum=(currentArea-1)*numCount 1; <br>var tempTaxNumber=currentArea*numCount 1; <br>this.maxNum=tempTaxNumber>pageCount?pageCount:tempTaxNumber; <br>this.preAreaNum=currentAreathis.afterAreaNum=currentArea>=lastArea?pageCount:this.maxNum 1; <br>} <br>var pageCount=0;//总页数 <br>pageCount=recordCount%pageSize===0?recordCount/pageSize:parseInt(recordCount/pageSize) 1;//总页数 <br> // var pager=document.getElementById('pager');//获取分页的要素 <br>// var pagesummary=document.createElement('span');//创建一个DIV,在里面显示第几页共几页 <br>// var summaryContent=document.createTextNode('第' currentPage '页共' pageCount '页'); <br>// pagesummary.appendChild(summaryContent); <br>// pager.appendChild(pagesummary); <br>CreateHref(url,1,'pager','首页',currentPage);// 首页链接を追加 <br>CreateHref(url,new GetNumArea(currentPage,numCount,pageCount).preAreaNum,'pager','< ;<',currentPage);// 前の省略号を追加 <BR>//分页数字の開始を表示 <BR>var pageArea = pageCount / numCount;// 页幣区间 <BR>if(pageCount<numCount){ <BR> for(i=1;i<=pageCount;i ){ <BR>CreateHref(url,i,'pager',i,currentPage); <BR>} <BR>}else{ <BR>currentPage=currentPage>=pageCount?pageCount:currentPage; <br>var minNum=new GetNumArea(currentPage,numCount,pageCount).minNum; <br>var maxNum=new GetNumArea(currentPage,numCount,pageCount).maxNum; <br>for(i=minNum;i<maxnum>CreateHref(url,i,'pager',i,currentPage); <br>} <br>} <br>//显示分页数字结束 <br>CreateHref(url,new GetNumArea(currentPage,numCount,pageCount).afterAreaNum,'pager','>>',currentPage); //表示分页裏面の省略号 <br>CreateHref(url,pageCount,'pager','末页',currentPage);//追加末页链 <br>} <br></script> <br><div id='pager'></div> <br></body> <br></html><br></maxnum> </div>