html页面之间传参数
1.html里面内容
1 | <a |
1 | href="a.html?param=value&param1=value1&param2=value2"> |
1 | 超链接 |
1 | </a> |
a.html里面内容
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
/**
* 获取参数的键值对对象。
* @returns {Object}
*/
var getParam = function () {
try{
var url = window.location.href;
var result = url.split("?")[1];
var keyValue = result.split("&");
var obj = {};
for (var i = 0; i < keyValue.length; i++) {
var item = keyValue[i].split("=");
obj[item[0]] = item[1];
}
return obj;}catch(e){
console.warn("There has no param value!");
}
};
/**
* 页面加载完毕打印键值对对象
*/
window.onload = function () {
console.log(getParam());
}
</script>
</head>
<body>
</body>
</html>