js 获取访问链接参数

js code:

function GetRequestPara()
{
	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]]=(strs[i].split("=")[1]); 
		} 
	}
	return Request;
}

使用:

var a1= RequestPara['a1'];
var a2= RequestPara['a2'];

访问链接是:http://10.10.16.161:8080/test/servlet?a1=3&a2=3

上述获取参数时: a1  =  3 , a2 = 3

相关文章
相关标签/搜索