<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>温故而知“心”</title>
</head>
<body>
</body>
<script>
/*
你如何获取浏览器URL中查询字符串中的参数?
测试地址为:
http://www.runoob.com/jquery/misc-trim.html?channelid=12333&name=xiaoming&age=23
*/
function urlSite() {
const getHref = window.location.href;
const array1 = getHref.split("?");
const array2 = array1[1].split("&");
const obj = {};
for (let i = 0; i < array2.length; i++) {
let obj2 = array2[i].split("=");
obj[obj2[0]] = obj2[1];
}
return obj;
}
const urlObj = urlSite();
console.log(urlObj.name)
// let obj = {};
// obj["name"]= "xyz";
// console.log(obj)//{name: "xyz"}
</script>
</html>
来源:CSDN
作者:&XYZ&
链接:https://blog.csdn.net/JEFF_luyiduan/article/details/104737524