当前位置:首页 > 资讯动态 > 网站建站 >

查看更多资讯中心

一个页面通过URL向另一个页面传递简单数据2019-01-21 来源:蓝典网络

内容摘要:test1.html !DOCTYPEhtml html head meta charset = utf-8 title test1.html页面 / title script type = text/javascript src = ../js/jquery-1.11.1.js / script / head body 请输入: input type = text id = txta br / 第一种方式,传输入的...

test1.html

 
 
  1. <!DOCTYPE html>
  2. <html>  
  3.     <head>  
  4.         <meta charset="utf-8">  
  5.         <title>test1.html页面</title>  
  6.         <script type="text/javascript" src="../js/jquery-1.11.1.js"></script>  
  7.     </head>  
  8.     <body>  
  9.         请输入:  
  10.         <input type="text" id="txta" >  
  11.         <br />  
  12.         第一种方式,传输入的值  
  13.         <input type=button value="去往test2.html页面" onclick="tiaozhuan()" />   
  14.         <script type="text/javascript">  
  15.             var tiaozhuan = function(){  
  16.                 document.location.href ='test2.html?mydata1=' + $("#txta").val();  
  17.             }  
  18.         </script>  
  19.         <br />  
  20.         第二种方式,传固定的值  
  21.         <input type=button value="去往test2.html页面" onclick="document.location.href ='test2.html?mydata1=ciweigudingzhi';" />   
  22.     </body>  
  23. </html>  

test2.html

  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="utf-8">  
  5.         <title>test2.html页面</title>  
  6.     </head>  
  7.     <body>  
  8.         test1.html页面传来的值为:<input type=text id="txt1" />  
  9.         <script type="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>  


要做网站?580全包

咨询客服

蓝典客服热线 电话:0592-5325273 13950058311 微信:13950058311 客服QQ:1391796206
284028140
扫描二维码
添加客服微信

扫码关注

公众号:蓝典网络 (landianwl) 扫描二维码
关注蓝典公众号