`

使用JS在URL中传递参数

阅读更多

aa.htm是参数输入界面
bb.htm是参数接收处理界面

aa.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
function submit()
{
	var input1 = document.getElementById("inputid");
	window.open("bb.html?inputStr=" + input1.value);//传入参数
}
</script>
</head>
<body>
	<input type="text" id="inputid">
	<input type="button" onclick="submit()" value="提交">
</body>
</html>

 bb.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
//获得参数的方法
var request = 
{ 
	QueryString : function(val) 
	{ 
		var uri = window.location.search; 
		var re = new RegExp("" +val+ "=([^&?]*)", "ig"); 
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null); 
	}
}
window.onload=function(){
	var rt = request.QueryString("inputStr");
	document.getElementById("recive").value=rt;
	alert(rt);
}
</script>
</head>
<body>
接收到:<input id="recive">
</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics