当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript表单之间的数据传递

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 javascript表单之间的数据传递


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 363 ::
收藏到网摘: n/a

 

    今天有朋友问我关于用JAVASCRIPT来进行页面各表单之间的数据传递的问题,我以前也写过,不过从来没有注意,今天总结了一下,希望能够给大家一些帮助,也帮助我总结以前学过,用过的知识。

    一,最简单的就是同一个网页里的表单的数据传递。

     举个实例,一个网页上有两个表单,每个表单里一个文本框,一个按钮。点按钮互相对操作对方的文本框的值。我们举的例子是把一个文本框付给另一个文本框。具体的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---------&gt;2" onClick="ok()">
</form>

<form name="form2" method="post" action="">
  <input type="text" name="textfield2">
  <input type="button" name="Submit" value="2-----&gt;1" onClick="ok1()">
</form>

</body>
</html>
 
  以上为HTMl的代码,大家可能注意到了onclik的代码了,有两个函数,接下来就是JAVASCRIPT的代码了:

 <script language="JavaScript">
function ok()
{
  document.form2.textfield2.value=document.form1.textfield.value;
}
function ok1()
{
document.form1.textfield.value=document.form2.textfield2.value;
}
</script>