java分页源码

1/5/2008来源:Java教程人气:8372


  <!--
*******************************************************
*        将一下代码存于page.htm,放在web server目录下    *
*        访问如:http://127.0.0.1/page.htm             *
*        实现了javascript的分页!                      *
*        PRogrammer:zero *Date:10/10/2001             *
*        www.net7b.com                                *
*******************************************************
-->
<SCRIPT language="javascript">
//初始化信息
//asp程序可以附值给数组生成js文件
var news=new Array();
for(var i=0;i<3000;i=i+1)
{
news[i]=i;
//document.writeln(news[i]+"<br>");
}


var countsize;
countsize=news.length;
var page;
var pagesize;
pagesize=10;
var pagecount;
pagecount=countsize/pagesize;
var j;
j=Math.round(pagecount)-pagecount;
if(j<=0.5)
{
j=Math.round(pagecount)-1;
}
else
{
j=Math.round(pagecount);
}
pagecount=j;
var spage;
var XPage;
var sspage;
var ss=location.href,ss2=location.pathname,ss3=location.hostname;
var kk=ss.length-ss2.length-ss3.length-7-1;
var page=ss.substring(ss.length-kk,ss.length);
if (page>=pagecount)
{
xpage=pagecount;
}
else
{
sspage=page
xpage=++sspage;
}
if (page<=1)
{
spage=0;
}
else
{
spage=page-1;
}
var ipage;
ipage=page*pagesize;
var pageover;
pageover=ipage+pagesize;
if (pageover>countsize)
{
pageover=countsize;
}
for(i=ipage;i<pageover;i=i+1)
{
document.writeln(news[i]+"<br>");
}
//分页
</SCRIPT>
<Html>
<head>