代码语言:javascript复制
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
/**
* 删除当前url中指定参数
* @param names 数组或字符串
* @returns {string}
*/
function delQueStr(url, ref) //删除参数值
{
var str = "";
if (url.indexOf('?') != -1)
str = url.substr(url.indexOf('?') 1);
else
return url;
var arr = "";
var returnurl = "";
var setparam = "";
if (str.indexOf('&') != -1) {
arr = str.split('&');
for (i in arr) {
if (arr[i].split('=')[0] != ref) {
returnurl = returnurl arr[i].split('=')[0] "=" arr[i].split('=')[1] "&";
}
}
return url.substr(0, url.indexOf('?')) "?" returnurl.substr(0, returnurl.length - 1);
}
else {
arr = str.split('=');
if (arr[0] == ref)
return url.substr(0, url.indexOf('?'));
else
return url;
}
}
let url='http://test.****.top:9000/activity/eth-staking?apptoken=123&id=999'
console.log(delQueStr(url,'apptoken'))
</script>
</html>