javascript - Reliably hide Bootstrap modal - Stack Overflow

I'm using Bootstrap 2.3.2, and I'm using modal dialogs like this:<div id="notice1&quo

I'm using Bootstrap 2.3.2, and I'm using modal dialogs like this:

<div id="notice1" class="modal hide fade">
    <div class="modal-body">
        <h4>This is a dialog for user...</h4>
    </div>
    ...
</div>

and

var notice1 = $("#notice1");
notice1.modal({
    keyboard: false,
    backdrop: "static",
    show: false
});

// Show the dialog
notice1.modal("show");

// Close the dialog
notice1.modal("hide");

Most of the the time, the above works fine and the modal dialog are opened and closed programmatically. However, in some rare cases, calling .modal("hide") does not close the dialog at all though the dark backdrop is removed.

This is a huge potential issue because the dialog may get stuck on the screen and block part of the content.

Is there a reliable way to ensure the dialog is always closed after calling .modal("hide")? Or better yet, how do we ensure a consistent hide behavior from Bootstrap? I don't want to remove the dialog pletely from the DOM, because the same dialog may be re-used on the page.

I'm using Bootstrap 2.3.2, and I'm using modal dialogs like this:

<div id="notice1" class="modal hide fade">
    <div class="modal-body">
        <h4>This is a dialog for user...</h4>
    </div>
    ...
</div>

and

var notice1 = $("#notice1");
notice1.modal({
    keyboard: false,
    backdrop: "static",
    show: false
});

// Show the dialog
notice1.modal("show");

// Close the dialog
notice1.modal("hide");

Most of the the time, the above works fine and the modal dialog are opened and closed programmatically. However, in some rare cases, calling .modal("hide") does not close the dialog at all though the dark backdrop is removed.

This is a huge potential issue because the dialog may get stuck on the screen and block part of the content.

Is there a reliable way to ensure the dialog is always closed after calling .modal("hide")? Or better yet, how do we ensure a consistent hide behavior from Bootstrap? I don't want to remove the dialog pletely from the DOM, because the same dialog may be re-used on the page.

Share Improve this question edited Nov 20, 2013 at 16:13 zessx 68.8k29 gold badges138 silver badges164 bronze badges asked Oct 21, 2013 at 14:05 MListerMLister 10.4k18 gold badges67 silver badges93 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You can hide the modal by using the following code.

 $("#notice1").hide();
 $(".modal-backdrop").hide();

According to documentation: http://getbootstrap./2.3.2/javascript.html#modals

You can catch the hidden event and force the display:none property.

    notice1.on('hidden', function () {
      $(this).css("display", "none")
    })

I am using 1.9.x, below code working..

$("#yourModalWindow").modal('hide');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745246037a4618414.html

相关推荐

  • javascript - Reliably hide Bootstrap modal - Stack Overflow

    I'm using Bootstrap 2.3.2, and I'm using modal dialogs like this:<div id="notice1&quo

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信