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

用javascript写的分页,为什么点击下一页不好使呢,大家来看看!
<%@ page language="java" contentType="text/html; charset=GB18030"
  pageEncoding="GB18030"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<script language="JavaScript">
var p = 10;
var t = new Array();
t[0] = "利用JavaScript实现网页分页技术1|01.htm|2012.6.18|wwcljs";
t[1] = "利用JavaScript实现网页分页技术2|02.htm|2012.6.18|wwcljs";
t[2] = "利用JavaScript实现网页分页技术3|03.htm|2012.6.18|wwcljs";
t[3] = "利用JavaScript实现网页分页技术4|04.htm|2012.6.18|wwcljs";
t[4] = "利用JavaScript实现网页分页技术5|05.htm|2012.6.18|wwcljs";
t[5] = "利用JavaScript实现网页分页技术6|06.htm|2012.6.18|wwcljs";
t[6] = "利用JavaScript实现网页分页技术7|07.htm|2012.6.18|wwcljs";
t[7] = "利用JavaScript实现网页分页技术8|08.htm|2012.6.18|wwcljs";
t[8] = "利用JavaScript实现网页分页技术9|09.htm|2012.6.18|wwcljs";
t[9] = "利用JavaScript实现网页分页技术10|10.htm|2012.6.18|wwcljs";
t[10] = "利用JavaScript实现网页分页技术11|11.htm|2012.6.18|wwcljs";
t[11] = "利用JavaScript实现网页分页技术12|12.htm|2012.6.18|wwcljs";
t[12] = "利用JavaScript实现网页分页技术13|13.htm|2012.6.18|wwcljs";
t[13] = "利用JavaScript实现网页分页技术14|14.htm|2012.6.18|wwcljs";
t[14] = "利用JavaScript实现网页分页技术15|15.htm|2012.6.18|wwcljs";
t[15] = "利用JavaScript实现网页分页技术16|16.htm|2012.6.18|wwcljs";
t[16] = "利用JavaScript实现网页分页技术17|17.htm|2012.6.18|wwcljs";
t[17] = "利用JavaScript实现网页分页技术18|18.htm|2012.6.18|wwcljs";
t[18] = "利用JavaScript实现网页分页技术19|19.htm|2012.6.18|wwcljs";
t[19] = "利用JavaScript实现网页分页技术20|20.htm|2012.6.18|wwcljs";
t[20] = "利用JavaScript实现网页分页技术21|21.htm|2012.6.18|wwcljs";
t[21] = "利用JavaScript实现网页分页技术22|22.htm|2012.6.18|wwcljs";
t[22] = "利用JavaScript实现网页分页技术23|23.htm|2012.6.18|wwcljs";
t[23] = "利用JavaScript实现网页分页技术24|24.htm|2012.6.18|wwcljs";
t[24] = "利用JavaScript实现网页分页技术25|25.htm|2012.6.18|wwcljs";
t[25] = "利用JavaScript实现网页分页技术26|26.htm|2012.6.18|wwcljs";

var totalPage = Math.ceil(t.length / p);
var curPage = 1;

var str = window.location.toString();//.toString()

if (str.indexOf("?") == -1) {
str = str + "?1";
}

r = str.split("?");
curPage = parseInt(r[1], 10);

w();

if (curPage > 1)
document.write("<a href=" + r[0] + "?" + (curPage - 1) + ">上一页</a>");
else
document.write("上一页");
document.write(" 第" + ((curPage - 1) * p) + "至");
if (curPage < totalPage)
document.write(curPage * p);
else
document.write(t.length);
document.write("条,总共有" + t.length + "条信息! ");
if (curPage < totalPage)
document.write("<a href=" + r[0] + "?" + (curPage + 1) + ">下一页</a>");
else
document.write("下一页");

function w() {
var c = new Array();

if (curPage >= totalPage) {
b = t.length;
s = (totalPage - 1) * p;
} else {
b = curPage * p;
s = (curPage - 1) * p;
}
for (var i = s; i < b; i++) {
c = t[i].split("|");
document.write(" " + (i + 1)
+ "、文 章 标 题<a href="+c[1]+" target=_blank>" + c[0]
+ "</a>时间" + c[2] + "作者" + c[3] + "<br>");
}
}
</script>
</html>

----