java分页源码
发表于:2007-06-30来源:作者:点击数:
标签:
!-- ******************************************************* *将一下代码存于page.htm,放在web server目录下* *访问如:http://127.0.0.1/page.htm* *实现了 java script的分页!* *programmer:zero *Date:10/10/2001* *www .net 7b.com* ****************
<!--
*******************************************************
* 将一下代码存于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>
<title>
</title>
</head>
<body>
<script language="javascript">
document.write("<a href=page.htm?0>首页</a>|<a href=page.htm?"+spage+">上一页</a>|<a href=page.htm?"+xpage+">下一页</a>|<a href=page.htm?"+pagecount+">尾页</a>");
</script>
</body>
</html>
原文转自:http://www.ltesting.net