JS下一页代码,遇到2位数以上的9读取链接错误
时间:2010-06-02
来源:互联网
实现功能:序列的页码,链接到下一页。比如:001.htm,002.htm,003.htm......
遇到问题:009.htm的时候可以正常链接下一页是010.htm,但是到019的时候就出错了,望前辈们帮助解决或是有更好的实现代码希望不吝赐教,谢谢~!
源码如下:(另存为019.htm测试效果)
遇到问题:009.htm的时候可以正常链接下一页是010.htm,但是到019的时候就出错了,望前辈们帮助解决或是有更好的实现代码希望不吝赐教,谢谢~!
源码如下:(另存为019.htm测试效果)
<!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=gb2312" /> <title>019.htm</title> <script type="text/javascript"> function page(){ var temp = window.location.href; var reMatch = /^(.*[^0])(0*)(\d+)\.(\w+)$/; if(reMatch.test(temp)){ newHref = parseInt(RegExp.$3) + 1; newHref = ((newHref%10)!=0)?(RegExp.$1 + RegExp.$2 + newHref + "." + RegExp.$4):(RegExp.$1 + RegExp.$2.substring(0,RegExp.$2.length-1) + newHref + "." + RegExp.$4); var aNode = document.getElementById("pager"); aNode.setAttribute("href",newHref); } } window.onload = page; </script> </head> <body> <p><a id="pager" href="#">下一页</a></p> </body> </html>
提示:您可以先修改部分代码再运行
提示:您可以先修改部分代码再运行
作者: 1key 发布时间: 2010-06-02
<!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=gb2312" /> <title>019.htm</title> <script type="text/javascript"> function page(){ //var temp = window.location.href; var temp = 'http://test.com/039.htm'; var reMatch = /^.+\/(\d+)\.(\w+)$/, newHref; if(reMatch.test(temp)){ newHref = '000' + (parseInt(RegExp.$1, 10) + 1);//当前页码加1, 左侧补上三个0 newHref = newHref.substr(newHref.length - 3);//右截3位 var aNode = document.getElementById("pager"); aNode.setAttribute("href", newHref + '.' + RegExp.$2);//设置下一页的地址 } } window.onload = page; </script> </head> <body> <p><a id="pager" href="#">下一页</a></p> </body> </html>
提示:您可以先修改部分代码再运行
提示:您可以先修改部分代码再运行
作者: faeng220 发布时间: 2010-06-03
感谢版主的解答,不过通用性好像没有原来的强,原来文件名如abc001,abc002。。。或1-25,1-26。。。都可以链接下一页,只是遇到9的时候就会出错。貌似版主修改的版本只能局限在纯数字序列的文件名上。我不懂程序,如果问题不符合逻辑还请版主不要见笑 =.=
不过已经够用了,我把文件名规定死为001,002这样的序列就好了。非常非常感谢版主,多谢~
不过已经够用了,我把文件名规定死为001,002这样的序列就好了。非常非常感谢版主,多谢~
作者: 1key 发布时间: 2010-06-04

你举的例子中没有说文件名开头有别的东西吧,
文件名格式为:
字母数字.htm
<!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=gb2312" /> <title>019.htm</title> <script type="text/javascript"> function page(){ //var temp = window.location.href; var temp = 'http://test.com/hello039.htm'; var reMatch = /^.+\/([^\d]*)(\d+)\.(\w+)$/, newHref; if(reMatch.test(temp)){ newHref = '000' + (parseInt(RegExp.$2, 10) + 1);//当前页码加1, 左侧补上三个0 newHref = newHref.substr(newHref.length - 3);//右截3位 var aNode = document.getElementById("pager"); aNode.setAttribute("href", RegExp.$1 + newHref + '.' + RegExp.$3);//设置下一页的地址 } } window.onload = page; </script> </head> <body> <p><a id="pager" href="#">下一页</a></p> </body> </html>
提示:您可以先修改部分代码再运行
文件名格式为的例子(代码与上面的一样,只是URL地址不样):提示:您可以先修改部分代码再运行
纯数字.htm
<!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=gb2312" /> <title>019.htm</title> <script type="text/javascript"> function page(){ //var temp = window.location.href; var temp = 'http://test.com/039.htm'; var reMatch = /^.+\/([^\d]*)(\d+)\.(\w+)$/, newHref; if(reMatch.test(temp)){ newHref = '000' + (parseInt(RegExp.$2, 10) + 1);//当前页码加1, 左侧补上三个0 newHref = newHref.substr(newHref.length - 3);//右截3位 var aNode = document.getElementById("pager"); aNode.setAttribute("href", RegExp.$1 + newHref + '.' + RegExp.$3);//设置下一页的地址 } } window.onload = page; </script> </head> <body> <p><a id="pager" href="#">下一页</a></p> </body> </html>
提示:您可以先修改部分代码再运行
提示:您可以先修改部分代码再运行
作者: faeng220 发布时间: 2010-06-04
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28