简体   繁体   English

Bootstrap - Modal在隐藏时保持“display:block”

[英]Bootstrap - Modal keeps “display: block” when hidden

I have a bootstrap modal in my web app that keeps being displayed even when I launch myModal.modal('close'); 我的网络应用程序中有一个引导模式,即使我启动myModal.modal('close');也会继续显示myModal.modal('close'); . I am pretty stuck with that strange problem. 我很困惑这个奇怪的问题。

Approx. 约。 one in ten times, I have that display: block; 十分之一,我有那个display: block; staying after close. 关闭后留下来。 The modal is correctly hidden because I can't see it anymore but it is overlaying my entire page and I cannot click on anything. 模态被正确隐藏,因为我不能再看到它,但它覆盖了我的整个页面,我无法点击任何东西。

I tried to handle the close with : 我试图处理关闭:

$('#myModal').on('hidden.bs.modal', function () {
  $(this).css('display', 'none !important');
})

And this does not work, the modal div is still having style="display: block;" 这不起作用,模态div仍然具有style="display: block;"

Try these and let me know if they work. 试试这些,让我知道他们是否有效。

$('selector').css('z-index', '-999');
$('selector').css('margin-left', '-50000');
$('selector').css('margin-top', '-50000');

My first question is: do you have a custom style sheet where you might be overriding the style for #myModal? 我的第一个问题是:你有一个自定义样式表,你可能会覆盖#myModal的样式吗? If so, work to resolve that. 如果是这样,努力解决这个问题。

My second question is: what version of Bootstrap are you using? 我的第二个问题是:你使用的是什么版本的Bootstrap? I have seen a bug logged similar to this back in 2012. If possible, upgrade to the latest version of Bootstrap (3.3.4). 我在2012年看到过与此类似的错误。如果可能,请升级到最新版本的Bootstrap(3.3.4)。

My third question is: what are you clicking to do the close? 我的第三个问题是:你点击什么关闭? Is it the close button ( type="button" class="close" ) or is it a button with a data-dismiss="modal" attribute? 它是关闭按钮(type =“button”class =“close”)还是具有data-dismiss =“modal”属性的按钮?

If the close button, you could try this as long as you don't have other modals on the page: 如果关闭按钮,只要您在页面上没有其他模态,您就可以尝试这个:

$(".close").on( "click", function() {
    $("#myModal").hide();
});

This might be worth a shot, too (though, not the recommended approach): 这也许值得一试(但不是推荐的方法):

$("#myModal").on("hide",function(){
    $("#myModal").css("display", "none");
});

Ultimately, I agree with needing a demo as Amit and Yerko suggest as this seems odd. 最终,我同意需要Amit和Yerko的演示,因为这看起来很奇怪。 I have never run across something like this, and I have used bootstrap for a long while. 我从来没有碰过这样的事情,我已经使用了很长一段时间的bootstrap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM