純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>  

 通過test.html?user=abc&password=123&sysno=001的測試結果來看,截獲參數的目的達到了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM