现在的位置: 首页 > 综合 > 正文

纯HTML页面之间传递参数

2013年05月17日 ⁄ 综合 ⁄ 共 1844字 ⁄ 字号 评论关闭
  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>  

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

抱歉!评论已关闭.