【发布时间】:2015-02-22 06:44:53
【问题描述】:
我正在尝试编写一个函数,该函数将使用一组名为 1.html、2.html、3.html、4.html 等的 html 页面,每个页面上都有上一个和下一个按钮。单击上一个或下一个箭头按钮将带我到浏览器中的下一个 html 页面。所以如果我在一个名为“2.html”的页面上,它会知道,并带我到“3.html”
我看到很多分页脚本,但这要简单得多。我想实际转到另一个 html 页面。我有一些这样的代码,但它没有像我预期的那样工作——谁能帮忙...?
function nextPg(step) {
var str = window.location.href;
if(pNum = str.match(/(\d+)\.html/i)){
pNum = pNum[1] * 1 + step+'';
if(pNum>0){
pNum = "".substr(0, 4-pNum.length)+pNum;
window.location = str.replace(/\d+\.html/i, pNum+'.html');
}
}
}
<a href="nextPg(+1)">Next Page »</a>
我尝试了@void 的建议并像这样编辑了代码,但仍然无法让它工作以加载我的名为“page2.html”的下一页
$( "#target" ).keyup(function( event ) {
function newDoc(){
var url = window.location.href;
url = url.split('/').pop();
curr = +curr.replace("page","").replace(".html","");
window.location.href = "page"+ (curr+1) +".html";
}
})
$( "#other").click(function() {
$( "#target" ).keyup();
});
我的按钮如下所示:
<button id="other">LOAD ANOTHER PAGE</button>
【问题讨论】:
-
为什么不使用cookies?
标签: javascript jquery jquery-pagination