[JQuery] 真正意義上清空表單內容

來源:互聯網
上載者:User

[JQuery] 真正意義上清空表單內容
JQuery :not() 選取器

定義與用法:

:not() 選取器選取除了指定元素以外的所有元素。

最常見的用法:與其他選取器一起使用,選取指定組合中除了指定元素以外的所有元素。

參考代碼:

<script>$(function() {$("p:not(#p1)").css("color", "red"); //寫法一$("p").not("#p1").css("color", "red"); //寫法二})</script>

Hello

Hello Again

執行結果:


HTML DOM reset() 方法或是 元素

參考代碼:

<script>$(function() {$("#form1 :input").val("value");})</script>
點擊重設按鈕前:


點擊重設按鈕後:


得出結論:HTML DOM reset() 方法或是 元素的真正作用並不是“清空” 元素中的 value值,而是“重設”還原 元素中的原本的 value 值。值得注意的是,reset 不能重設按鈕類型元素(type=button,reset,submit)的 value 值。


真正清空 form 表單中的內容(JQuery)

參考代碼:

<script>$(function() {$("#button").click(function() {$("#form :input").not(":button, :submit, :reset, :hidden").val("").removeAttr("checked").remove("selected");//核心});})</script>真正清空
點擊“id=button”的按鈕前:


點擊"id=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.