URL中递增的数字-jQuery/JavaScript

URL中递增的数字-jQuery/JavaScript,javascript,jquery,pagination,jquery-pagination,Javascript,Jquery,Pagination,Jquery Pagination,我有一个类似http://blog.com/post/1我需要一个函数来更新它末尾的数字,以便分页 到目前为止,我已经: window.location(document.URL++); 您可以通过以下方式执行此操作: var url = document.URL; var pagenumber = url.substr(url.length-1); window.location = '/post/'+pagenumber++; 但这是一个黑客,你可以做你的项目结构更好,不需要这样做 va

我有一个类似
http://blog.com/post/1
我需要一个函数来更新它末尾的数字,以便分页

到目前为止,我已经:

window.location(document.URL++);
您可以通过以下方式执行此操作:

var url = document.URL;
var pagenumber = url.substr(url.length-1);
window.location = '/post/'+pagenumber++;
但这是一个黑客,你可以做你的项目结构更好,不需要这样做

var url  = window.location.href.split('/'),
    page = parseInt(url.pop(), 10);

// to go to next page, increment page number and join with URL

window.location.href = url.join('/') +'/'+ (++page);

使用书签增加URL中的最后一个数字(通常是页码):

javascript:url=window.location.href;
newurl=url.replace(/(\d+)([^0-9]*)$/, function(t,x,y){return parseInt(x,10)+1+y});
window.location.href=newurl;

什么是URL++?URL是一个变量名吗?请添加更多详细信息。@harsha否我试图使用document.URL获取当前URL。不确定为什么会被否决?@sanjaypoyzer我不知道获取URL上的数字是否是最好的方法。因为您的代码将被限制为这种格式。如果需要更改url,则需要更改大量代码。您只能处理1个数字。@sanjaypoyzer它不能处理超过一个数字的页码。增加页码是个好主意,在转到同一页时没有用?啊,它不能处理超过一个数字的页面,这绝对是个问题。如果没有此故障,是否可以执行此操作?将最坏的保存到最后,
位置
不是一项功能!这似乎是从1跳到9,然后什么也不做。@sanjaypoyzer oops,一个小错误,在regexp中忘记了+。它正在工作,请格式化您的代码,以增加可读性。
javascript:url=window.location.href;
newurl=url.replace(/(\d+)([^0-9]*)$/, function(t,x,y){return parseInt(x,10)+1+y});
window.location.href=newurl;