a.html
window.open("a.htm?id='1'", "dss", "newwindow");
b.htm
<script type="text/javascript">
var str = location.search;
var num = str.indexOf("?");
str = str.substr(num + 1);
alert(str);
var arrtmp = str.split("&");
for (i = 0; i < arrtmp.length; i++) {
num = arrtmp[i].indexOf("=");
if (num > 0) {
name = arrtmp[i].substring(0, num);
value = arrtmp[i].substr(num + 1);
this[name] = value;
}
}
alert(this["id"]);
</script>
本文介绍了一种通过JavaScript解析URL中的查询字符串并提取参数的方法。具体实现包括获取查询字符串、分割参数名与参数值,并将它们存储为JavaScript对象中便于后续使用。

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



