日期:2014-05-16  浏览次数:20444 次

简单的JS分页代码
<script language=javascript>

	function WritePager(pageIndex,pageCount,pageName,ext){
		if(pageCount>1){
			var pagelen=7;
			var startPage=pageIndex-3;
			if(startPage<0) startPage=0;
			var endpage=pagelen+startPage;
			if(endpage>pageCount)endpage=pageCount;
			
			startPage=endpage-7;
			if(startPage<0) startPage=0;
			if(pageIndex>1)	{	
				document.write("<a href=\""+pageName+"."+ext+"\">首页</a>&nbsp;");	   
				document.write("&nbsp;<a href=\""+pageName+"_"+(pageIndex-1)+"."+ext+"\">上一页</a>&nbsp;");
				}
			else if(pageIndex==1){
				document.write("<a href=\""+pageName+"."+ext+"\">首页</a>&nbsp;");
				document.write("&nbsp;<a href=\""+pageName+"."+ext+"\">上一页</a>&nbsp;");
				}
			else{
				document.write("&nbsp;首页</a>&nbsp;");
				document.write("&nbsp;上一页&nbsp;");
				}
				
			for(var i=startPage;i<endpage;i++){
				if(i==pageIndex){
					document.write("&nbsp;<font color=red>"+(i+1)+"<\/font>&nbsp;");
				}else if(i==0){
					document.write("&nbsp;<a href=\""+pageName+"."+ext+"\">"+(i+1)+"</a>&nbsp;");
				}else{
					document.write("&nbsp;<a href=\""+pageName+"_"+i+"."+ext+"\">"+(i+1)+"</a>&nbsp;");
				}
			}
			if(pageIndex<pageCount-1){
				document.write("&nbsp;<a href=\""+pageName+"_"+(pageIndex+1)+"."+ext+"\">下一页</a>&nbsp;");
				document.write("<a class='pagebar' href=\"" + pageName + "_" + (pageCount-1) + "." + ext + "\">尾页</a>");
				}
			else{
				document.write("&nbsp;下一页&nbsp;");
				document.write("&nbsp;尾页</a>");
				}

		}
	}
	WritePager(0,100,"index","html");
</script>

?

1 楼 hastune 2011-09-20  
博主论坛的帖子锁了。我没能回复。

采用Array.join比字符串+的方式快。
2 楼 vtrtbb 2011-09-22  
哦,我试试