删掉链接上参数的方法
作者:互联网
// 删除url参数
function urlDelP(url,name){
var urlArr = url.split('?');
if(urlArr.length>1 && urlArr[1].indexOf(name)>-1){
var query = urlArr[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 urlte = urlArr[0] +'?'+ JSON.stringify(obj).replace(/["{}]/g,"").replace(/:/g,"=").replace(/,/g,"&");
return urlte;
}else{
return url;
};
}
标签:arr,obj,url,删掉,urlArr,replace,参数,var,链接 来源: https://www.cnblogs.com/zhaoshuxin/p/16502070.html