location.search在客户端获取Url参数的方法

最近一直在写html,刚接触到,感觉挺复杂的。。比如传参,在.net里可以直接用Request接受,而在html中还要经过处理,找了一些资料,写了个方法。

复制代码 代码如下:


var id;
function getid()
{
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
{
var str = url.substr(1) //去掉?号
strs = str.split("&");
for(var i=0;i<strs.length;i++)
{
Request[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
id=Request["id"];
document.getElementById('td_fa').innerHTML=id + "页面信息";
}


这样就好办了。。。传参和.net一样"http://www.aaa.html?id=1"就可以了。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdxxfs.html