删除url中某个参数

    //删除url中某个参数
        funcUrlDel(loca, name){
            let baseUrl='';
            if(loca.indexOf('&')>-1) {
                 baseUrl = loca.split('?')[0]+'?';
            } else {
                 baseUrl = loca.split('?')[0];
            }
            let query = loca.split('?')[1];
            if(query&&query.indexOf(name)>-1) {
                var obj = {};
                var arr = query.split("&");
                for(var i = 0; i < arr.length; i++) {
                    arr[i] = arr[i].split("=");
                    obj[arr[i][0]] = arr[i][1];
                }
                delete obj[name];
                var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
                return url;
            } else {
                return loca;
            }
        }

 

posted @ 2020-10-28 13:14  GavinJay  阅读(2272)  评论(0编辑  收藏  举报