纯HTML页面之间传递参数

  1. <html>  
  2. <head>  
  3.     <meta http-equiv="Content-Type" content="html/text; charset=utf-8"/>  
  4.     <title>JS get Parameter</title>  
  5.     <script src="resource/js/param.js" type="text/javascript"></script>  
  6. </head>  
  7. <body>  
  8. <table>  
  9.     <tr>  
  10.         <td><input type="text" name="user" /></td>  
  11.         <td><input type="text" name="password" /></td>  
  12.         <td><input type="text" name="sysno" /></td>  
  13.     </tr>  
  14. </table>  
  15. </body>  
  16. <script type="text/javascript">  
  17.     var LocString=String(window.document.location.href);   
  18.        
  19.     function getQueryStr(str){   
  20.         var rs = new RegExp("(^|)"+str+"=([^/&]*)(/&|$)","gi").exec(LocString), tmp;   
  21.        
  22.         if(tmp=rs){   
  23.             return tmp[2];   
  24.         }   
  25.        
  26.         // parameter cannot be found   
  27.         return "";   
  28.     }   
  29.   
  30.     document.getElementById("user").value = getQueryStr("user");   
  31.     document.getElementById("password").value = getQueryStr("password");   
  32.     document.getElementById("sysno").value = getQueryStr("sysno");   
  33. </script>  
  34. </html>  
<html>
<head>
	<meta http-equiv="Content-Type" content="html/text; charset=utf-8"/>
	<title>JS get Parameter</title>
	<script src="resource/js/param.js" type="text/javascript"></script>
</head>
<body>
<table>
	<tr>
		<td><input type="text" name="user" /></td>
		<td><input type="text" name="password" /></td>
		<td><input type="text" name="sysno" /></td>
	</tr>
</table>
</body>
<script type="text/javascript">
	var LocString=String(window.document.location.href);
	
	function getQueryStr(str){
		var rs = new RegExp("(^|)"+str+"=([^/&]*)(/&|$)","gi").exec(LocString), tmp;
	
		if(tmp=rs){
			return tmp[2];
		}
	
		// parameter cannot be found
		return "";
	}

	document.getElementById("user").value = getQueryStr("user");
	document.getElementById("password").value = getQueryStr("password");
	document.getElementById("sysno").value = getQueryStr("sysno");
</script>
</html>

 通过test.html?user=abc&password=123&sysno=001的测试结果来看,截获参数的目的达到了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值