function getQueryStringArgs() {
var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
args = {},
items = qs.length ? qs.split("&") : [],
item = null,
name = null,
value = null,
i = 0,
len = items.length;
for(i = 0; i < len; i++) {
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length) {
args[name] = value;
}
}
return args;
}
用法:
getQueryStringArgs().name
本文介绍了一个JavaScript函数,用于解析URL中的查询字符串,并将其转换为键值对形式的对象。该方法适用于网页应用中从URL获取参数的场景。
1966

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



