// 获取url后面指定名称的查询参数
function getUrlQueryString(name) {
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
// window.location.search 从?开始的部分,包括?
var r = window.location.search.substr(1).match(reg);
if (r) {
return unescape(r[2]);// 对通过escape()编码的字符串进行解码
}
return null;
}
// 获取url的查询参数组成的对象
function getUrlQueryObj() {
//获取url中"?"符后的字串
var url = location.search;
var queryObj = {};
if (url.indexOf("?") > -1) {
var str = url.substr(1);
strs = str.split("&");
strs.forEach((item) => {
queryObj[item.split("=")[0]] = unescape(item.split("=")[1]);
});
}
return queryObj;
}
网友评论