js 截取url参数 生成数组对象
//获取url参数
function GetRequest() {
//获取url参数
var url = window.location.search;
//创建数组
var theRequest = new Object();
//判断?是否存在,以此判断是否有参数
if (url.indexOf("?") != -1) {
//拆分成['value=name']
var str = url.substr(1).split("&");
//循环遍历
str.forEach(item => {
theRequest[item.split("=")[0]] = decodeURIComponent(item.split("=")[1]);
});
}
console.log(theRequest);
return theRequest;
}
使用
let data = GetRequest()
console.log(data)