javascript 添加,修改 url中的参数

版权声明:廖圣平博客,未经博主允许不得转载。企鹅:1194008361 https://blog.csdn.net/qq_22823581/article/details/88342883
   var url = 'http://mp.test/admin/MpStatistics/firmList.html?sldf=2323&page=2323';
   console.log(changeURLArg(url,'page','laji'))




    function changeURLArg(url,arg,arg_val){
        var pattern=arg+'=([^&]*)';
        var replaceText=arg+'='+arg_val;
        if(url.match(pattern)){
            var tmp='/('+ arg+'=)([^&]*)/gi';
            tmp=url.replace(eval(tmp),replaceText);
            return tmp;
        }else{
            if(url.match('[\?]')){
                return url+'&'+replaceText;
            }else{
                return url+'?'+replaceText;
            }
        }
    }

没有更多推荐了,返回首页