Javascript 修改 URL 参数

String.prototype.changeQuery = function(name,value) { var reg = new RegExp("(^|)"+ name +"=([^&]*)(|$)"); var tmp = name + "=" + value; if(this.match(reg) != null) { return this.replace(eval(reg),tmp); } else { if(this.match("[/?]")) { return this + "&" + tmp; } else { return this + "?" + tmp; } } } var href = 'http://dlib.apabi.com/?Token=44AB&cult=CN&orgid=pku'; alert("old url is -- "+href); href = href.changeQuery("cult","US"); alert("new url is -- "+href); 

你可能感兴趣的:(JavaScript,function,null,url)