js获取URL参数

<Script language="javascript"> 
function GetRequest() { 
var url = decodeURI(location.search); //获取url中"?"符后的字串,使用decodeURI()来解析汉字乱码问题  
var theRequest = new Object(); 
if (url.indexOf("?") != -1) { 
var str = url.substr(1); 
strs = str.split("&"); 
for(var i = 0; i < strs.length; i ++) { 
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
} 
} 
return theRequest; 
} 
</Script> 

调用方法: 
<Script language="javascript"> 
var Request = new Object(); 
Request = GetRequest(); 
var 参数1,参数2,参数3,参数N; 
参数1 = Request['参数1']; 
参数2 = Request['参数2']; 
参数3 = Request['参数3']; 
参数N = Request['参数N']; 
</Script>

 

使用出处(非常感谢):http://www.jb51.net/article/41274.htm

http://blog.csdn.net/sinat_29843547/article/details/47379259

 

posted @ 2017-06-19 17:02  蜗牛的礼物  阅读(237)  评论(0编辑  收藏  举报