www.site.com/potato/hello/eweb/TestPage.aspx
// or
www.site.com/potato/eweb/TestPage.aspx
我想從使用jQuery無論eweb
前的網址是多長的URL eweb
之前搞定一切。
因此,從上面的示例#1中,我想要得到www.site.com/potato/hello/
和www.site.com/potato/
作爲我的結果。
www.site.com/potato/hello/eweb/TestPage.aspx
// or
www.site.com/potato/eweb/TestPage.aspx
我想從使用jQuery無論eweb
前的網址是多長的URL eweb
之前搞定一切。
因此,從上面的示例#1中,我想要得到www.site.com/potato/hello/
和www.site.com/potato/
作爲我的結果。
您可以通過eweb
split()
當前URL並獲得結果數組的第一個元素:
var baseUrl = window.location.href.split('eweb')[0];
嘗試使用String.prototype.match()
與RegExp
/.*(?=eweb)/
匹配,其次是 「EWEB」
var str = "www.site.com/potato/hello/eweb/TestPage.aspx";
var res = str.match(/.*(?=eweb)/)[0];
console.log(res)
感謝您的提示,這個作品也很棒! –
工作正常!感謝您的幫助! –
沒問題,很樂意幫忙。 –