how to destroy bootstrap modal window completely?

后端 未结 24 733
旧时难觅i
旧时难觅i 2020-11-29 18:51

I\'ve made use of modal window for a wizard implementation which has around 4,5 steps. I need to destroy it completely after the last step(

相关标签:
24条回答
  • 2020-11-29 19:00

    If modal shadow remains darker and not going for showing more than one modal then this will be helpful

    $('.modal').live('hide',function(){
        if($('.modal-backdrop').length>1){
            $('.modal-backdrop')[0].remove();
        }
    });
    
    0 讨论(0)
  • 2020-11-29 19:03
    $('#myModal').on('hidden.bs.modal', function () {
          $(this).data('bs.modal', null).remove();
    });
    
    //Just add .remove(); 
    //Bootstrap v3.0.3
    
    0 讨论(0)
  • 2020-11-29 19:04

    My approach would be to use the clone() method of jQuery. It creates a copy of your element, and that's what you want : a copy of your first unaltered modal, that you can replace at your wish : Demo (jsfiddle)

    var myBackup = $('#myModal').clone();
    
    // Delegated events because we make a copy, and the copied button does not exist onDomReady
    $('body').on('click','#myReset',function() {
        $('#myModal').modal('hide').remove();
        var myClone = myBackup.clone();
        $('body').append(myClone);
    });
    

    The markup I used is the most basic, so you just need to bind on the right elements / events, and you should have your wizard reset.

    Be careful to bind with delegated events, or rebind at each reset the inner elements of your modal so that each new modal behave the same way.

    0 讨论(0)
  • 2020-11-29 19:06

    If you have an iframe in your modal, you can remove its content by the following code:

    $('#myModal').on('hidden.bs.modal', function(){
       $(this).find('iframe').html("");
       $(this).find('iframe').attr("src", "");
    });
    
    0 讨论(0)
  • 2020-11-29 19:07

    I don't know how this may sound but this work for me...........

    $("#YourModalID").modal('hide');
    
    0 讨论(0)
  • 2020-11-29 19:08

    Single line complete removal on hide ( ES6 )

    $("#myModal").on('hidden.bs.modal', (e)=>e.currentTarget.remove());

    0 讨论(0)
提交回复
热议问题