当前位置:编程学习 > JS >>

同一页面两个表单互相传值的JavaScript

有时候我们在提交表单的时候需要将两个表单的值互相传递,那么如何实现呢?其实很简单,就是用JavaScrip获取任一表单的值,然后赋给另一个,具体可看代码,代码很有意思,也很实用。
答案:<html>
<head>
<title>同一页面两个表单互相传值的JavaScript</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<script language="JavaScript">
function ok()
{
  document.form2.textfield2.value=document.form1.textfield.value;
}
function ok1()
{
document.form1.textfield.value=document.form2.textfield2.value;
}
</script>
<body>
<form name="form1" method="post" action="">
  <input type="text" name="textfield">
  <input type="button" name="Submit" value="A表单->传值给B表单" onClick="ok()">
</form>
<form name="form2" method="post" action="">
  <input type="text" name="textfield2">
  <input type="button" name="Submit" value="B表单->传值给A表单" onClick="ok1()">
</form>
</body>
</html>

上一个:点击按钮后,按钮文字会改变
下一个:给一段代码加入按钮点击后运行的功能

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,