js获取url参数并生成对象
假设链接/index.html?id=1&code=101&type=2
/**
* @description: 获取url参数对象
*/
function url() {
if (window.location.href.split("?").length > 1) {
var newurl = window.location.href.split("?")[1].split("&")
var obj = {}
for (let i in newurl) {
var itemArray = newurl[i]
var item = itemArray.split("=")
obj[item[0]] = item[1]
}
return obj
}
}
console.log(url());