我们说我有以下网址:
www.mydomain.com/default.aspx?param1=value1¶m2=value2¶m3=value3
OR
www.mydomain.com/default.aspx?param2=value2¶m1=value1
OR
www.mydomain.com/default.aspx?param3=value3¶m1=value1¶m2=value2
如何只删除部分" param1 = value1"从那些使用jQuery或Javascript的URL地址?
答案 0 :(得分:2)
试试这个: -
function RemoveParam(url, p) {
return url
.replace(new RegExp('[?&]' + p + '=[^&#]*(#.*)?$'), '$1')
.replace(new RegExp('([?&])' + p + '=[^&]*&'), '$1');
}
var url='www.mydomain.com/default.aspx?param3=value3¶m1=value1¶m2=value2'
alert(RemoveParam(url,'param1'));
答案 1 :(得分:1)
试
var url = "www.mydomain.com/default.aspx?param3=value3¶m1=value1¶m2=value2"
url = url.replace("¶m1=value1", "");