0
点赞
收藏
分享

微信扫一扫

Js_表单间数据传递


一,同一个网页里的表单的数据传递。 



 



举个实例,一个网页上有两个表单,每个表单里一个文本框,一个按钮。点按钮互相对操作对方的文本框的值。我们举的例子是把一个文本框付给另一个文本框。具体的HTML代码如下: 



 

<html> 
 
 
 

  <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> 
 
 
 

  <body> 
 
 
 

  <form name="form1" method="post" action=""> 
 
 
 

  <input type="text" name="textfield"> 
 
 
 

  <input type="button" name="Submit" value="1--------->2" onClick="ok()"> 
 
 
 

  </form> 
 
 
 

  <form name="form2" method="post" action=""> 
 
 
 

  <input type="text" name="textfield2"> 
 
 
 

  <input type="button" name="Submit" value="2----->1" onClick="ok1()"> 
 
 
 

  </form> 
 
 
 

  </body> 
 
 
 

  </html> 
 
 
 

   
 
 
 

  function ok() 
 
 
 

  { document.form2.textfield2.value=document.form1.textfield.value; } 
 
 
 

  function ok1() 
 
 
 

  { document.form1.textfield.value=document.form2.textfield2.value; }



 



二,第二种是两个窗口之间的表单的文本框之间数据传递。


function ok() { opener.document.form2.textfield2.value=document.form1.textfield.value }



 



三,第三种就是框架网页之间的表单的文本框之间数据传递. 


<frameset cols="505,505"> 
 
 
 

  <frame src="test.htm" name="leftr" id="leftr">//定义框架的名称 
 
 
 

  <frame src="test2.htm" id="right" name="right"> 
 
 
 

  </frameset> 
 
 
 

  <noframes><body> 
 
 
 

  </body></noframes> 
 
 
 

   
 
 
 

  function ok() { parent.leftr.document.form2.textfield2.value=document.form1.textfield.value }


举报

相关推荐

0 条评论