HTML一個頁面輸入值跳轉到另一個頁面並且顯示出來
阿新 • • 發佈:2019-01-01
- <spanstyle="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">test1.html</span>
- <spanstyle="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
- </span>
- <spanstyle="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html
- <html>
- <head>
- <metacharset="utf-8">
- <title>test1.html頁面</title>
- <scripttype="text/javascript"src="../js/jquery-1.11.1.js"></script>
- </head>
- <body>
- 請輸入:
- <inputtype="text"id="txta">
- <
- 第一種方式,傳輸入的值
- <inputtype=buttonvalue="去往test2.html頁面"onclick="tiaozhuan()"/>
- <scripttype="text/javascript">
- var tiaozhuan = function(){
- document.location.href ='test2.html?mydata1=' + $("#txta").val();
- }
- </script
- <br/>
- 第二種方式,傳固定的值
- <inputtype=buttonvalue="去往test2.html頁面"onclick="document.location.href ='test2.html?mydata1=ciweigudingzhi';"/>
- </body>
- </html>
test2.html
- <!DOCTYPE html>
- <html>
- <head>
- <metacharset="utf-8">
- <title>test2.html頁面</title>
- </head>
- <body>
- test1.html頁面傳來的值為:<inputtype=textid="txt1"/>
- <scripttype="text/javascript">
- var txt1 = document.getElementById("txt1");
- txt1.value = location.search.match(new RegExp("[\?\&]mydata1=([^\&]+)", "i"))[1];
- </script>
- </body>
- </html>