English 中文(简体)
• 如何将目前的《欧洲刑法》改写为 j?
原标题:How to change the current URL in javascript?
  • 时间:2012-01-14 23:07:28
  •  标签:
  • javascript

在我的网站上:

http://mywebsite.com/1.html

我想利用这个机会。

window.location.pathname

a. 进入月球最后部分:

1.html

既然我有所有网页,我想在目前的档次中增加一页,以便在我点一个 but子时,把我转往下页:

var url =  http://mywebsite.com/  + window.location.pathname;
function nextImage (){
url = url + 1;  
}

any ideas why this is not working ?

最佳回答

你的榜样是,你试图在看上去的插图中增加1个:“1.html”。 这只会使你们看到不是你们想要的“1.html1”。 你们必须把扼杀的体数部分分开,然后将其改为实际数字,然后才能用数字。 在实际数字之后,你可以提高价值,然后将其与其余方结合起来。

You can use a custom replace function like this to isolate the various pieces of the original URL and replace the number with an incremented number:

function nextImage() {
    return(window.location.href.replace(/(d+)(.html)$/, function(str, p1, p2) {
        return((Number(p1) + 1) + p2);
    }));
}

你们可以这样说:

window.location.href = nextImage();

页: 1

这将使任何数字的升温潜能值在一定系列数中结束,然后是.html,如果你需要略微不同的URL表格,你就只能夸大经常表达。

问题回答

这更加有力:

mi = location.href.split(/(d+)/);
no = mi.length - 2;
os = mi[no];
mi[no]++;
if ((mi[no] +   ).length < os.length) mi[no] = os.match(/0+/) + mi[no];
location.href = mi.join(  );

当《欧洲刑法》有多个编号时,它将改变最后一点:

http://mywebsite.com/8815/1.html

它支持人数最多的零:

http://mywebsite.com/0001.html

Even it is not a good way of doing what you want try this hint: var url = MUST BE A NUMER FIRST

function nextImage (){
url = url + 1;  
location.href= http://mywebsite.com/  + url+ .html ;
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签