How to clear all input fields in bootstrap modal when clicking data-dismiss button?

后端 未结 10 831
情话喂你
情话喂你 2020-12-04 10:58

How to clear all input fields in a Bootstrap V3 modal when clicking the data-dismiss button?

10条回答
  •  死守一世寂寞
    2020-12-04 11:35

    In addition to @Malk, I wanted to clear all fields in the popup, except the hidden fields. To do that just use this:

    $('.modal').on('hidden.bs.modal', function () {
        $(this)
            .find("input:not([type=hidden]),textarea,select")
            .val('')
            .end()
            .find("input[type=checkbox], input[type=radio]")
            .prop("checked", "")
            .end();
    });
    

    This will clear all fields, except the hidden ones.

提交回复
热议问题