<html> <head><title>1.html</title></head> <body> <a href="2.html?code=123&pp=321">value between the htmls </a> </body> </html>
<html>
<head><title>2.html</title></head>
<body>
<center>
<input type="test" id="parameterName1"/>
<input type="test" id="htmlCode1"/><br>
<input type="test" id="parameterName2"/>
<input type="test" id="htmlCode2"/>
</center>
<script type="text/javascript">
var parameterName = "parameterName", // 统一参数名前缀
unifiedIdName = "htmlCode", // 统一参数值前缀
name, // 参数名
values, // 参数值
tmpArr, // 第三变量数组
QueryString, // 问号之后的URL字符串
whyIndex, // 问号的下标索引
URL = document.location.toString(); // URL地址
if(URL.lastIndexOf("?") != -1){
QueryString = URL.substring(URL.lastIndexOf("?")+1, URL.length); // 判断URL是否带参数传递
tmpArr = QueryString.split("&"); // 分离参数地址中and符号的每一个参数块
for (var i=0; i < tmpArr.length; i++) {
whyIndex = tmpArr[i].indexOf("=");
if(whyIndex > 0){
name = tmpArr[i].substring(0, whyIndex) ; // 获取参数名
values = tmpArr[i].substring(whyIndex + 1) ; // 获取参数值
document.getElementById(parameterName + (i + 1) + "").value = name ; // 给指定id赋参数名
document.getElementById(unifiedIdName + (i + 1) + "").value = values ; // 给指定id赋参数值
}
}
} else {
QueryString = "";
}
</script>
</body>
</html>
传值都是一样的,在这里我就随便用一个浏览器测试给大家看下吧。
360浏览器显示效果:
原文地址:http://blog.csdn.net/imwangjiping/article/details/39322769