2016-04-28 47 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很高兴帮助! –

相关问题