js替换url里面的变量
Others 2018-04-02 05:51:19 2018-04-02 05:51:19 2307 次浏览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; }
Links: 116