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

后端 未结 10 857
情话喂你
情话喂你 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:24

    There is a more easy and beautiful way:

    $('#MyModal').on('hidden.bs.modal', function () {
        $(this).find('form').trigger('reset');
    })
    

    reset is dom build-in funtion, you can also use $(this).find('form')[0].reset();

    And Bootstrap's modal class exposes a few events for hooking into modal functionality, detail at here.

    hide.bs.modal This event is fired immediately when the hide instance method has been called.

    hidden.bs.modal This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).

提交回复
热议问题