zywang 发表于 2013-2-7 15:19:28

使用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"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).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> 
页: [1]
查看完整版本: 使用JS在URL中传递参数