function UpdateUrlParam(name, val) {
var thisURL = document.location.href;
if (thisURL.indexOf(name+'=') > 0) {
var v = getUrlParam(name);
if (v != null) {
thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
}
else {
thisURL = thisURL.replace(name + '=', name + '=' + val);
}
}
else {
if (thisURL.indexOf("?") > 0) {
thisURL = thisURL + "&" + name + "=" + val;
}
else {
thisURL = thisURL + "?" + name + "=" + val;
}
}
location.href = thisURL;
};
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
来源:CSDN
作者:tang05709
链接:https://blog.csdn.net/tang05709/article/details/104427335