2016-04-28 44 views
1

我想在JavaScript中的兩個字符之間搜索字符串,jQuery。如何在jQuery中的兩個字符之間搜索字符串

這裏ID我的網址

http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type= 「藝術家,魔術」。

我想在"status=" and first &之間搜索字符串,這樣當我得到比這個更大的值時,我可以放入URL。

+0

是你想怎麼辦得到的參數? –

+0

雅,實際上我想把狀態的值,如果它從下拉列表中選擇後更改 – Vikash

+0

'var str ='http://local.evibe-dash.in/vendors/new?status = Phone&count = 60&type = 「藝術家,魔術'」。 str.substring(str.indexOf('status =')+ 7,str.indexOf('&'))' –

回答

1

使用match()與捕獲組正則表達式

var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,m‌​agic".'; 
 

 
var res = str.match(/status=([^&]+)/)[1] 
 

 
document.write(res);


,或者使用split()

var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,m‌​agic".'; 
 

 
var res = str.split('status=')[1].split('&')[0]; 
 

 
document.write(res);


或使用substring()indexOf()

var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,m‌​agic".', 
 
    ind = str.indexOf('status='); 
 

 
var res = str.substring(ind + 7, str.indexOf('&', ind)); 
 

 
document.write(res);

+0

謝謝。你解決了我動態刷新網址的問題。 – Vikash

+0

@Vikash很高興幫助! –

相關問題