純HTML頁面之間傳遞參數

來源:互聯網
上載者:User
  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 foundreturn "";}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的測試結果來看,截獲參數的目的達到了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.