本来想用网上找来的分页程序,不过都得做修改,感觉麻烦了,还是自己写一个好了,以后自己用的时候修改就方便了~~大家都多动手,自己写的才是最好的,日后想干什么的,做修改也是很容易的~~顺便也扩充一下自己的代码库~~ 补充一句,cpage是页面计数,应为全局变量,这样可以随处调用它,totalpage是总页数 JS静态分页程序 a:link,a:visited,a:hover,.current,#info{ border:1px solid #DDD; background:#F2F2F2; display:inline-block; margin:1px; text-decoration:none; font-size:12px; width:15px; height:15px; text-align:center; line-height:15px; color:#AAA; padding:1px 2px; } a:hover{ border:1px solid #E5E5E5; background:#F9F9F9; } .current{ border:1px solid #83E7E4; background:#DFF9F8; margin:1px; color:#27CBC7; } #info{ width:auto; } <!-- var totalpage,pagesize,cpage,count,curcount,outstr; //初始化 cpage = 1; totalpage = 56; pagesize = 10; outstr = ""; function gotopage(target) { cpage = target; //把页面计数定位到第几页 setpage(); //reloadpage(target); //调用显示页面函数显示第几页,这个功能是用在页面内容用ajax载入的情况 } function setpage() { if(totalpage<=10){ //总页数小于十页 for (count=1;count<=totalpage;count++) { if(count!=cpage) { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'>"+count+""; }else{ outstr = outstr + "<span class='current' >"+count+""; } } } if(totalpage>10){ //总页数大于十页 if(parseInt((cpage-1)/10) == 0) { for (count=1;count<=10;count++) { if(count!=cpage) { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'>"+count+""; }else{ outstr = outstr + "<span class='current'>"+count+""; } } outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'> next "; } else if(parseInt((cpage-1)/10) == parseInt(totalpage/10)) { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+(parseInt((cpage-1)/10)*10)+")'>previous"; for (count=parseInt(totalpage/10)*10+1;count<=totalpage;count++) { if(count!=cpage) { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'>"+count+""; }else{ outstr = outstr + "<span class='current'>"+count+""; } } } else { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+(parseInt((cpage-1)/10)*10)+")'>previous"; for (count=parseInt((cpage-1)/10)*10+1;count<=parseInt((cpage-1)/10)*10+10;count++) { if(count!=cpage) { outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'>"+count+""; }else{ outstr = outstr + "<span class='current'>"+count+""; } } outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'> next "; } } document.getElementById("setpage").innerHTML = "<div id='setpage'><span id='info'>共"+totalpage+"页|第"+cpage+"页<\/span>" + outstr + "<\/div>"; outstr = ""; } setpage(); //调用分页 //--> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]