how to destroy bootstrap modal window completely?

2019-01-10 05:34发布

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(onFinish) and OnCancel step without having a page refresh. I can of course hide it, but hiding modal windows restores everything as such when i open up it again. Could anyone help me on this issue?

Thanks Any hints answers are helpful for me.

24条回答
做个烂人
2楼-- · 2019-01-10 05:58

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

$("#YourModalID").modal('hide');
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-10 06:00

if is bootstrap 3 you can use:

$("#mimodal").on('hidden.bs.modal', function () {
    $(this).data('bs.modal', null);
});
查看更多
趁早两清
4楼-- · 2019-01-10 06:00

For 3.x version

$( '.modal' ).modal( 'hide' ).data( 'bs.modal', null );

For 2.x version (risky; read comments below) When you create bootstrap modal three elements on your page being changed. So if you want to completely rollback all changes, you have to do it manually for each of it.

$( '.modal' ).remove();
$( '.modal-backdrop' ).remove();
$( 'body' ).removeClass( "modal-open" );
查看更多
ら.Afraid
5楼-- · 2019-01-10 06:00

Also works on bootstrap 4.x

$('#modal_ID').modal( 'hide' ).data( 'bs.modal', null );
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-10 06:00

This worked for me.

$('.modal-backdrop').removeClass('in');
$('#myDiv').removeClass('in');

The dialog and backdrop went away, but they came back the next time I clicked the button.

查看更多
Rolldiameter
7楼-- · 2019-01-10 06:02

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();
});
查看更多
登录 后发表回答