本文實例講述了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>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答