jQuery 引导模式弹出窗口未关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18464081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:40:31  来源:igfitidea点击:

bootstrap modal popup not closing

javascriptjquerytwitter-bootstrappopupmodal-dialog

提问by dreagan

I'm having trouble using a bootstrap modal popup. Calling a popup is no issue, but trying to close it yields strange results. Instead of just hiding the popup and removing the backdrop, the popup gets hidden but another backdrop gets added, turning the screen almost black. the original backdrop does not get removed.

我在使用引导模式弹出窗口时遇到问题。调用弹出窗口没有问题,但尝试关闭它会产生奇怪的结果。不是仅仅隐藏弹出窗口和删除背景,弹出窗口被隐藏但另一个背景被添加,使屏幕几乎变黑。原始背景不会被移除。

Below is the html code I've tried to use

下面是我尝试使用的 html 代码

<div id="popupDelete" class="modal hide fade" role="dialog">
    <div class="modal-header">delete transaction line?</div>
    <div class="moda-body">
        <button id="deleteYes">yes</button>
        <button class="cancelButton" data-dismiss="modal">no</button>
    </div>
</div>

this is what I got from the bootstrap 2.3 docs and should work out of teh bix, like everything else from bootstrap.

这是我从 bootstrap 2.3 文档中得到的,应该在 bix 中工作,就像 bootstrap 中的其他所有内容一样。

I've also tried using javascript with the $('#popupDelete').modal('hide');function, which had the same effect.

我也试过在$('#popupDelete').modal('hide');函数中使用 javascript ,它具有相同的效果。

采纳答案by dreagan

There was indeed javascript conficting with the closing of the popup. There was a line of javascript messing with all popups when clicking on a parent container, forcing them open again.

确实有 javascript 与弹出窗口的关闭发生冲突。单击父容器时,有一行 javascript 会干扰所有弹出窗口,迫使它们再次打开。

回答by S.p

This one worked for me

这个对我有用

$('#popupDelete').modal('toggle');

回答by morten.c

I'm not sure if this is causing the problem, but there is a typo. It's

我不确定这是否是导致问题的原因,但有一个错字。它是

<div class="modal-body">

in line 3. There is missing an "l"

在第 3 行。缺少一个“l”

回答by Fitsum Belayneh

Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You'll likely run into issues when nesting a .modalwithin another fixed element.

只要有可能,将模态 HTML 放在顶级位置,以避免其他元素的潜在干扰。.modal在另一个固定元素中嵌套 a 时,您可能会遇到问题。

回答by RONE

@dreagan, it may be happening like, when you click on open button for example, the popup is created dynamically, So you may be required the close Try this :

@dreagan,它可能会发生,例如,当您单击打开按钮时,弹出窗口是动态创建的,因此您可能需要关闭试试这个:

$('#popupDelete').close()

OR

或者

$.modal.close();

Refer this How do you close a jQuery Simplemodal?

请参阅此 如何关闭 jQuery Simplemodal?

回答by Kushal

<script>   $('#submit').click( function () {
$('#myModal').modal('hide');     }); </script>
<script>   $('#submit').click( function () {
$('#myModal').modal('hide');     }); </script>