js获取request参数

function request(strParame) { 
	var args = new Object( ); 
	var query = location.search.substring(1); 
	
	var pairs = query.split("&"); // Break at ampersand 
	for(var i = 0; i < pairs.length; i++) { 
	var pos = pairs[i].indexOf('='); 
	if (pos == -1) continue; 
	var argname = pairs[i].substring(0,pos); 
	var value = pairs[i].substring(pos+1); 
	value = decodeURIComponent(value); 
	args[argname] = value; 
	} 
	return args[strParame]; 
}

 

用法:

a.html?test=1

request("test");

转载于:https://my.oschina.net/u/2613449/blog/603131

你可能感兴趣的:(js获取request参数)