2017-01-16 31 views

回答

0

好吧,如果這是在路徑的同一部分,你可以這樣做:

var mystr = url.split('/')[5]; 
0

如果它始終是這個數字的/在此之後將工作的console.log(location.href.split( '/')[5]);

0

試試這個

document.location.pathname.split('/')[3] 
0
var url = "https://subdomain.mysite.com/abc/xyz/MYID9878797878/page/#/route1/step1/step2"; 

var parameter3 = url.split('/')[5]; 
//OR var parameter3 = location.href.split('/')[5]; 

// console.log(parameter3) or alert(parameter3) 
+0

是否有可能不使用拆分,即不依賴索引?我知道它始終以MYID – testndtv

+0

開頭,那麼請嘗試JavaScript String match()方法。 –

+0

示例代碼var maches = url.match(/ MYID(。*)\/page /); –