<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 전환//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>본문{글꼴 크기:12px;} <br>#pager{높이:20px; float:left;} <br>#pager a{높이:18px; 줄 높이:18px; 테두리:1px 솔리드 #ccc; 왼쪽 패딩:0.4em; 오른쪽 패딩:0.4em; 텍스트 장식:없음; 표시:블록; 부동:왼쪽; 여백:0px 3px;} <br>#pager a:hover{배경색상:#1f3a87; 색상:#fff; 텍스트 장식:없음;} <br>.not-current{배경 색상:#fff; 색상:#1f3a87;} <br>.current{배경색:#1f3a87; 색상:#fff; 텍스트 장식:없음;} <br></style> <br></head> <br><body onload="CreatePager(10,10,2043,'?page=14',10)"> <br><script type="text/javascript"> <br>//pageSize,每页显示多少条记录,currentPage当前页,recordCount共多少条记录,url页路径,必须带有page参数,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(' 에이'); <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=currentArea<=1?1:this.minNum-1; <BR>this.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;i ){ <BR>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> </div>