文字框擷取焦點後點擊斷行符號提交和不提交

來源:互聯網
上載者:User

     

文字框擷取焦點後點擊斷行符號提交和不提交:
在有些時候為了方便,可能有這樣的需求,那就是當表單中的文字框擷取焦點的時候,點擊enter斷行符號鍵能夠實現表單提交功能,但是有些時候我們不希望有類似的功能,比如表單比較龐大,辛辛苦苦填寫了半天表單,一個斷行符號誤操作,導致表單提交。實現上述兩種功能通常使用javascript,其實使用css也是可以粗略做到此功能。
(1).一個文字框的時候,提交按鈕type不管是submit還是button,文字框獲得焦點,點擊斷行符號會提交:
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 < form action = "http://www.softwhy.com" >    < input type = "text" >    < input type = "button" value = "提交" > </ form >
(2).一個文字框的時候怎麼才能做到不提交,方法是加一個隱藏掉的文字框:
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 5 < form action = "http://www.softwhy.com/" >    < input type = "text" >    < input type = "text" style = "display:none" >    < input type = "button" value = "提交" > </ form >
(3).只要有type為submit的按鈕存在,一個文字框還是多個文字框都提交:
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 < form action = "http://www.softwhy.com/" >    < input type = "text" >    < input type = "submit" value = "提交" > </ form >
上面是一個文字框的情況。
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 5 < form action = "http://www.softwhy.com/" >    < input type = "text" >    < input type = "text" >    < input type = "submit" value = "提交" > </ form >
上面是多個文字框的情況。
(4).多個文字框的時候,不提交,用type為button的按鈕即可:
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 5 < form action = "http://www.softwhy.com/" >    < input type = "text" >    < input type = "text" >    < input type = "button" value = "提交" > </ form >
(5).type為image的按鈕,等同於type為submit的效果:
[HTML] 純文字查看 複製代碼運行代碼 1 2 3 4 5 < form action = "http://www.softwhy.com/" >    < input type = "text" >    < input type = "text" >    < input type = "image" src = "images/antzone.jpg" > </ form >
總結如下:
(1).如果表單裡有一個type=”submit”的按鈕,斷行符號鍵生效。
(2).如果表單裡只有一個type=”text”的input,不管按鈕是什麼type,斷行符號鍵生效。
(3).如果按鈕不是用input,而是用button,並且沒有加type,IE下預設為type=button,FF預設為type=submit。
(4).其他表單元素如textarea、select不影響,radio checkbox不影響觸發規則,但本身在FF下會響應斷行符號鍵,在IE下不響應。
(5).type=”image”的input,效果等同於type=”submit”,不知道為什麼會設計這樣一種type,不推薦使用,應該用CSS添加背景圖合適些。

聯繫我們

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