js替换url里面的变量
emer 发布于 2018-4-2 13:51 2286 次阅读
function replaceParamVal(paramName,replaceWith) { var oUrl = this.location.href.toString(); var re=eval('/('+ paramName+'=)([^&]*)/gi'); if (re.test(oUrl)){ var nUrl = oUrl.replace(re,paramName+'='+replaceWith); }else{ if(oUrl.indexOf('?')>0){ var nUrl = oUrl+"&"+paramName+"="+replaceWith; }else{ var nUrl = oUrl+"?"+paramName+"="+replaceWith; } } this.location=nUrl; }