how to destroy bootstrap modal window completely?

后端 未结 24 735
旧时难觅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:10

    I had to use same modal for different link clicks. I just replaced the html content with empty "" of the modal in hidden callback.

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

    It works for Bootstrap v3.3.6

    $('#dialog').modal()
    .on('hide.bs.modal', function () {
        // Some Code
    }).on('shown.bs.modal', function () {
        // Some Code
    }).on('hidden.bs.modal', function () {
        $("#dialog").off();
    });
    
    0 讨论(0)
  • 2020-11-29 19:14

    bootstrap 3 + jquery 2.0.3:

    $('#myModal').on('hide.bs.modal', function () {
       $('#myModal').removeData();
    })
    
    0 讨论(0)
  • 2020-11-29 19:15

    From what i understand, you don't wanna remove it, nor hide it ? Because you might wanna reuse it later ..but don't want it to have the old content if ever you open it up again ?

    <div class="modal hide fade">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times</button>
            <h3>Modal header</h3>
        </div>
        <div class="modal-body">
            <p>One fine body…</p>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn">Close</a>
            <a href="#" class="btn btn-primary">Save changes</a>
        </div>
    </div>
    

    If you wanna use it as a dynamic template just do something like

    $(selector).modal({show: true})
    
    ....
    
    $(selector).modal({show: false})
    $(".modal-body").empty()
    
    ....
    
    $(".modal-body").append("new stuff & text")
    $(selector).modal({show: true})
    
    0 讨论(0)
  • 2020-11-29 19:16

    I had a same scenario where I would open a new modal on a button click. Once done, I want to completely remove it from my page... I use remove to delete the modal.. On button click I would check if modal exists , and if true I would destroy it and create a new modal ..

    $("#wizard").click(function() {
        /* find if wizard is already open */
        if($('.wizard-modal').length) {
            $('.wizard-modal').remove();
        }
    });
    
    0 讨论(0)
  • 2020-11-29 19:17

    This is my solution:

    this.$el.modal().off();

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