javascript表單之間的資料傳遞

來源:互聯網
上載者:User
資料

    今天有朋友問我關於用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--------->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的代碼了:

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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.