转自于此,话不多说,直接上代码
var url = window.location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
}
}
console.log(theRequest);

这段代码展示了如何在JavaScript中解析URL查询字符串。通过location.search获取URL参数,然后使用split和decodeURI方法处理,创建一个对象存储键值对,便于访问参数。
1万+

被折叠的 条评论
为什么被折叠?



