javascript表单之间的数据传递

王朝html/css/js·作者佚名  2005-06-06
窄屏简体版  字體: |||超大  

今天在编写程序的时候遇到两个网页间数据的传递问题。

到网上搜索了一大堆的相关资料,终于把问题给解决了。

问题的解决很大部分得归功于javascript的应用,其中尤为重要的是javascript的DOM技术。

下面是页面间常见的一些数据传递问题,以及实现代码。

1:同一个页面间,两个FORM之间的参数传递

<html>

<head>

<title>大鱼之家</title>

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

</head>

<body>

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

<input type="text" name="test1" value=">

<input type="button" name="Submit" value="change_test2" onClick="ok1()">

</form>

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

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

<input type="button" name="Submit" value="change_test1" onClick="ok2()">

</form>

</body>

</html>

<script language="javascript">

function ok1()

{

document.form2.test2.value=document.form1.test1.value;

}

function ok2()

{

document.form1.test1.value=document.form2.test2.value;

}

</script>

由上可见。其中主要是对文档对象document的使用。关于文档对象document的使用方法可以参考以下文章

:http://www.channel7.cn/bbs/showthread.asp?threadid=506

2:网页与弹出页面之间的数据传递:

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

<body>

<form name="my" method="post" action="#">

<input type="text" name="hehe" value="ffff">

</form>

<a href=# onclick="javascript:open('top-

hehehehe.asp','','scrollbars=yes,width=400,height=200')"><img

src="admin/images/edit/UpFile.gif" alt=上传文件 width="22" height="22" border=0

style="cursor: hand;"></a>

</body>

</html>

top-hehehehe.asp页面代码:

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

<form name="bigfish" method="post" action="#">

<input type="text" name="hehe" value="Hei,Wo is your name?">

</form>

<body>

</body>

</html>

<script language="javascript">

opener.document.my.hehe.value=document.bigfish.hehe.value;

</script>

有关弹出页的使用方法可以参考如下文章:

http://www.channel7.cn/bbs/showthread.asp?threadid=512(说得非常详细)

http://www.channel7.cn/bbs/showthread.asp?threadid=503

3:页面与框架页面之间的数据传递

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

<body>

<iframe src="top-hehehehe.asp" id="message" align=center></iframe>

<form name="my" method="post" action="#">

<input type="text" name="hehe" value="ffff">

</form>

</body>

</html>

top-hehehehe.asp页面代码:

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

<form name="bigfish" method="post" action="#">

<input type="text" name="hehe" value="Hei,Wo is your name?">

</form>

<body>

</body>

</html>

<script language="javascript">

top.document.my.hehe.value=document.bigfish.hehe.value;

</script>

4:框架网页之间的表单的文本框之间数据传递

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

<body>

<iframe src="top-hehehehe.asp" id="message" align=center></iframe>

<iframe src="top-hehehehe1.asp" id="message1" align=center></iframe>

</body>

</html>

top-hehehehe.asp页面代码:

<html>

<head>

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

<title>数据传递-大鱼</title>

</head><body>

ID为message框架页

<form name="my" method="post" action="#">

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

</form>

</body>

</html>

top-hehehehe1.asp页面代码:

<html>

<head>

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

<title>数据传递-大鱼</title>

</head>

</html>

<script language="javascript">

parent.message.document.my.hehe.value="这是ID为message1框架内部表单项HEHE的值";

</script>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航