/技术
分类:技术来源:bobo最近更新:2020-09-10浏览:1247
/* 获得地址参数 */
/* ================================================== */
getParam = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
};
``````javascript
/* 设置地址参数 */
/* ================================================== */
setParam = function(name, value) {
var currentUrl = window.location.href.split('#')[0];
if (/\?/g.test(currentUrl)) {
if (/name=[-\w]{4,25}/g.test(currentUrl)) {
currentUrl = currentUrl.replace(/name=[-\w]{4,25}/g, name + "=" + value);
} else {
currentUrl += "&" + name + "=" + value;
}
} else {
currentUrl += "?" + name + "=" + value;
}
if (window.location.href.split('#')[1]) {
return currentUrl + '#' + window.location.href.split('#')[1];
} else {
return currentUrl;
}
};