html的兩種提交按鈕submit和button

來源:互聯網
上載者:User

標籤:blog   c   http   a   com   使用   

轉自:http://baiying.blog.51cto.com/1068039/1319784

html按鈕有兩種:

<input type="button" value="登入" onclick="login()"/>

和<button onclick="login()">登入</button>

這兩種在頁面上看起來好像一樣沒什麼區別,但是這兩種是有區別的。

1,如果在<form id="loginForm" name="loginForm" action="<%=path%>/hdlogin/login.action" method="post"></form>

標籤中,使用<input type="button" value="登入" onclick="login()"/>,要想提交form,

你必須寫成<input type="submit" value="登入" onclick="login()"/>,

或者document.loginForm.submit();否則form是不會提交的。

 

2,如果在form中使用<button onclick="login()">登入</button>只要點擊就會提交。

<button type="submit" value="登入" onclick="login()"/>。

 

今天在使用<button></button>時,我又在js控製表單提交,結果這個action總是莫名其妙的走兩次!

根源就是表單提交了兩次,一次是<button></button>,一次是document.loginForm.submit();

這個錯誤很隱蔽,大家以後要注意。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.