利用JavaScript方法实现静态html页面参数传递

mac2022-06-30  90

 原理是应用获得地址栏字串,进行分析。   aa.htm是参数输渗入渗出界面   bb.htm是参数接收处理界面   aa.htm 

1   <html> 2 3   <head> 4   </head> 5 6   <body> 7   <script> 8 9   function submit() 10 11   { 12 13   var input1 = document.getElementById("inputid"); 14 15   window.open("bb.htm?inputStr=" + input1.value);//传入参数 16 17   } 18 19   </script> 20 21   <input type = "text" id = "inputid"> 22 23   <input type = "button" onclick = "submit()" value = "提交"> 24 25   </body> 26 27   </html>

  bb.htm: 

1 <html> 2 3   <head> 4 5   <script> 6 7   //获得参数的方法 8 9   var request = 10 11   { 12 13   QueryString : function(val) 14 15   { 16 17   var uri = window.location.search; 18 19   var re = new RegExp("" +val+ "=([^&?]*)", "ig"); 20 21   return ((uri.match(re))?(uri.match(re)[0].substr(val.leng th+1)):null); 22 23   } 24 25   } 26 27   </script> 28 29   </head> 30 31   <body> 32 33   <script> 34 35   //调用方法获得参数 36 37   var rt = request.QueryString("inputStr"); 38 39   alert(rt); 40 41   </script> 42 43   </body> 44 45   </html>

 

  ====================================   

1 <html> 2 3   <head> 4 5   <title>test</title> 6 7   <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 8 9   <SCRIPT LANGUAGE="JavaScript"> 10 11   <!-- 12 13   var request = { 14 15   QueryString : function(val) { 16 17   var uri = window.location.search; 18 19   var re = new RegExp("" +val+ "=([^&?]*)", "ig"); 20 21   return ((uri.match(re))?(uri.match(re)[0].substr(val.leng th+1)):null); 22 23   } 24 25   } 26 27   var a = request.QueryString ("a"); 28 29   var b = request.QueryString ("b"); 30 31   var c = request.QueryString ("c"); 32 33   if ((a != null)){a=a} else{a="参数A空"} 34 35   if ((b != null)){b=b} else{b="参数B空"} 36 37   if ((c != null)){c=c} else{c="参数C空"} 38 39   document.writeln("参数A: " + a); 40 41   document.writeln("<br>参数B: " + b); 42 43   document.writeln("<br>参数C: " + c); 44 45   //--> 46 47   </SCRIPT> 48 49   </head> 50 51   <body> 52 53   <form name="form1" action="?"> 54 55   请输入参数值:<br> 56 57   <SCRIPT LANGUAGE="JavaScript"> 58 59   document.writeln("A:<input type='text' name='a' value='"+a+"'><br>"); 60 61   document.writeln("B:<input type='text' name='b' value='"+b+"'><br>"); 62 63   document.writeln("C:<input type='text' name='c' value='"+c+"'><br>"); 64 65   </SCRIPT> 66 67   <input type="submit" name="Submit" value="提交参数查观效果"> 68 69   </form> 70 71   </body> 72 73   </html>

 

转载于:https://www.cnblogs.com/QuentinYo/archive/2013/05/24/3098146.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)