循环,达到最大页数或最小页数,自动回到第1页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>西安Java培训</title>
</head>
<body>
<script>
function nextPg(step) {
// var step=1;
// alert('step is ' + step);
var MaxpNum = 5;
// document.write(MaxNum);
var str = window.location.href;
// alert(str);
if (pNum = str.match(/(\d+)\.html/i)) {
// alert("inside first if " + pNum);
pNum = pNum[1] * 1 + step + '';
// alert("pNum should be 2 now: " + pNum);
if ((pNum < 1) || (pNum > MaxpNum)) {
pNum = 1;
// pNum = "".substr(0, 4-pNum.length)+pNum;
window.location = str.replace(/\d+\.html/i, pNum + '.html');
// alert(window.location.href);
} // stop actions if not within range
else {
// alert("inside else");
pNum = "".substr(0, 4 - pNum.length) + pNum;
// alert(pNum);
window.location = str.replace(/\d+\.html/i, pNum + '.html');
// alert(window.location.href);
}
}
}
</script>
<p>第一页</p>
[ <a href="javascript:nextPg(-1)">« Previous Page</a> ] |
[ <a href="javascript:nextPg(+1)">Next Page »</a> ]
</body>
</html>
演示地址:http://188029.net/javascript/liulixin2.html
原文:http://www.webdeveloper.com/forum/showthread.php?226550-Javascript-Previous-and-Next-Page-function