|
javascript 参数传递 文本框
一,最简单的就是同一个网页里的表单的数据传递。
举个实例,一个网页上有两个表单,每个表单里一个文本框,一个按钮。点按钮互相对操作对方的文本框的值。我们举的例子是把一个文本框付给另一个文本框。具体的HTML代码如下:
Html代码
<html> <head> <title>Untitled Document</title> <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" > </form> <form name="form2" method="post" action=""> <input type="text" name="textfield2"> <input type="button" name="Submit" value="2----->1" > </form> </body> </html> <html><head><title>Untitled Document</title><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" ></form><form name="form2" method="post" action=""> <input type="text" name="textfield2"> <input type="button" name="Submit" value="2----->1" ></form></body></html> 以上为HTMl的代码,大家可能注意到了onclik的代码了,有两个函数,接下来就是JAVASCRIPT的代码了:Js代码 <script language="JavaScript"> function ok() { document.form2.textfield2.value=document.form1.textfield.value; } function ok1() { document.form1.textfield.value=document.form2.textfield2.value; } </script> <script language="JavaScript">function ok(){ document.form2.textfield2.value=document.form1.textfield.value;}function ok1(){document.form1.textfield.value=document.form2.textfield2.value;}</script>
二,第二种是两个窗口之间的表单的文本框之间数据传递。其实这个可以在原来的基础上进行一些扩展就可以了。关于如何创建弹出窗口,窗体里的表单的代码, 在这里就不多说了,现在在这里说一下如何操作父窗口的表单里的文本框的数据。具体代码如下:
Js代码
<script language="JavaScript"> function ok() { opener.document.form2.textfield2.value=document.form1.textfield.value } </script> <script language="JavaScript">function ok(){ opener.document.form2.textfield2.value=document.form1.textfield.value}</script>
三,第三种就是框架网页之间的表单的文本框之间数据传递.
注意的地方是框架的写法:
Html代码
<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>
具体的实现代码如下:
<script language="JavaScript"> function ok() { parent.leftr.document.form2.textfield2.value=document.form1.textfield.value } </script> <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>具体的实现代码如下:
<script language="JavaScript">function ok(){ parent.leftr.document.form2.textfield2.value=document.form1.textfield.value}</script>
这三种窗口之间的文本框数值互相操作的简单方法就实现了,其它需要注意的就是他们之间的关系。 |
|