How clear bootstrap modal on hide

后端 未结 3 583
庸人自扰
庸人自扰 2021-02-19 04:52

How to can you clear the bootstrap modal on dismiss/hide/close?

I have the following Modal definition:

相关标签:
3条回答
  • 2021-02-19 05:21

    this is the easiest fix:

    $('#myModal').on('hidden.bs.modal', function () {
        $(this).find("input,textarea,select").val('').end();
    
    });
    
    0 讨论(0)
  • 2021-02-19 05:33

    Use val('') based on input types present and use #myModal instead of body

    $('#myModal').on('hidden.bs.modal', function () {
            $('.modal-body').find('textarea,input').val('');
    });
    

    DEMO

    0 讨论(0)
  • 2021-02-19 05:43

    This worked for me

    $('body').on('hidden.bs.modal', '.modal', function () {
            $(".modal-content").empty();
          });
    
    0 讨论(0)
提交回复
热议问题