JS 获取静态页面的参数

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>JS 获取静态页面的参数</title>
</head>
<body>
<Script language="javascript">
function GetRequest() {
	//来源 http://localhost/demo/demo.html?aaa=onestopweb&bbb=demo&ccc=chaoyi
	//location.search 获取问号及后面的参数 ?aaa=onestopweb&bbb=demo&ccc=chaoyi
	var url = location.search;
	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;
}
var ClientRequest = GetRequest();
console.info(ClientRequest);
var ReauesKey = ClientRequest['aaa'];
document.write(ReauesKey);
</Script>
</body>
</html>

 

效果图:

 

 

 

 

 

 

你可能感兴趣的:(js,获取参数,获取静态页面的参数,获取静态页面的参数)