1. 程式人生 > >HTML一個頁面輸入值跳轉到另一個頁面並且顯示出來

HTML一個頁面輸入值跳轉到另一個頁面並且顯示出來

  1. <spanstyle="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">test1.html</span>
  1. <spanstyle="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
  2. </span>
  1. <spanstyle="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html
    ></span>
  1. <html>
  2.     <head>
  3.         <metacharset="utf-8">
  4.         <title>test1.html頁面</title>
  5.         <scripttype="text/javascript"src="../js/jquery-1.11.1.js"></script>
  6.     </head>
  7.     <body>
  8.         請輸入:  
  9.         <inputtype="text"id="txta">
  10.         <
    br/>
  11.         第一種方式,傳輸入的值  
  12.         <inputtype=buttonvalue="去往test2.html頁面"onclick="tiaozhuan()"/>
  13.         <scripttype="text/javascript">
  14.             var tiaozhuan = function(){  
  15.                 document.location.href ='test2.html?mydata1=' + $("#txta").val();  
  16.             }  
  17.         </script
    >
  18.         <br/>
  19.         第二種方式,傳固定的值  
  20.         <inputtype=buttonvalue="去往test2.html頁面"onclick="document.location.href ='test2.html?mydata1=ciweigudingzhi';"/>
  21.     </body>
  22. </html>

test2.html

  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <metacharset="utf-8">
  5.         <title>test2.html頁面</title>
  6.     </head>
  7.     <body>
  8.         test1.html頁面傳來的值為:<inputtype=textid="txt1"/>
  9.         <scripttype="text/javascript">
  10.             var txt1 = document.getElementById("txt1");  
  11.             txt1.value = location.search.match(new RegExp("[\?\&]mydata1=([^\&]+)", "i"))[1];  
  12.         </script>
  13.     </body>
  14. </html>