斷行符號鍵提交與不提交表單的解決方案

來源:互聯網
上載者:User

最近遇到IE6/7下敲擊斷行符號後表單不提交的問題,網上找到些資料,備案下:

 

斷行符號鍵提交表單:設定 <input /> 標籤或者 <button> 標籤的屬性 type="submit" 即可。

斷行符號鍵不提交表單,用JavaScript來解決,具體代碼如下:

document.getElementsByTagName('form')[0].onkeydown = function(e){    var e = e || event;    var keyNum = e.which || e.keyCode;    return keyNum==13 ? false : true;};

分析:

如果按鈕用 <input /> 標籤,標籤的 type="submit" ,IE6、7、8、Firefox斷行符號時均提交。

如果按鈕用 <input /> 標籤,標籤的 type="button" ,

1 沒有 <input type="text" value="" /> 斷行符號均不提交。
2 有一個 <input type="text" value="" /> , IE6、7下焦點在何處斷行符號均不會提交,IE8、只有焦點在 <input type="text" value="" /> 上時斷行符號才會提交, Firefox均斷行符號會提交。
3有多個 <input type="text" value="" /> ,IE6、7、8、Firefox均不會提交。

如果按鈕用 <input /> 標籤,標籤的 type="" ,E6、7、8、Firefox均會預設為 type="text" 。

如果按鈕用 <button> 標籤,標籤的 type="submit" ,E6、7、8、Firefox斷行符號時均提交。

如果按鈕用 <button> 標籤,標籤的 type="button" ,

1 沒有 <input type="text" value="" /> 斷行符號均不提交。
2 有一個 <input type="text" value="" /> , IE6、7下焦點在何處斷行符號均不會提交,IE8、只有焦點在<input type="text" value="" />上時斷行符號才會提交, Firefox均斷行符號會提交。
3 有多個 <input type="text" value="" /> ,IE6、7、8、Firefox均不會提交。

如果按鈕用 <button> ,標籤的 type="" ,IE6、7下預設的 type="button" ,IE6、7下焦點在何處斷行符號均不提交,IE8、Firefox預設為 type="submit" ,IE8、Firefox均斷行符號會提交。

http://www.joywebsite.com/2010/04/submit-or-donot-submit-form-on-enter-button/

聯繫我們

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