我想在JavaScript中的兩個字符之間搜索字符串,jQuery。如何在jQuery中的兩個字符之間搜索字符串
這裏ID我的網址
http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type= 「藝術家,魔術」。
我想在"status=" and first &
之間搜索字符串,這樣當我得到比這個更大的值時,我可以放入URL。
我想在JavaScript中的兩個字符之間搜索字符串,jQuery。如何在jQuery中的兩個字符之間搜索字符串
這裏ID我的網址
http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type= 「藝術家,魔術」。
我想在"status=" and first &
之間搜索字符串,這樣當我得到比這個更大的值時,我可以放入URL。
使用match()
與捕獲組正則表達式
var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".';
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,magic".';
var res = str.split('status=')[1].split('&')[0];
document.write(res);
var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".',
ind = str.indexOf('status=');
var res = str.substring(ind + 7, str.indexOf('&', ind));
document.write(res);
謝謝。你解決了我動態刷新網址的問題。 – Vikash
@Vikash很高興幫助! –
是你想怎麼辦得到的參數? –
雅,實際上我想把狀態的值,如果它從下拉列表中選擇後更改 – Vikash
'var str ='http://local.evibe-dash.in/vendors/new?status = Phone&count = 60&type = 「藝術家,魔術'」。 str.substring(str.indexOf('status =')+ 7,str.indexOf('&'))' –