我正在使用Twitter引导模态对话框。当我点击引导模式对话框的提交按钮时,它会发送一个AJAX请求。我的问题是情态背景并没有消失。模态对话框确实消失了,但是“模态背景”在屏幕上创建的不透明度仍然存在

我该怎么办?


当前回答

我正在和流星一起工作,我也遇到了同样的问题。我的bug的原因是:

{{#if tourmanager}}
    {{>contactInformation tourmanager}}
{{else}}
    <a href="#addArtistTourmanagerModal" data-toggle="modal"><i class="fa fa-plus"></i> Tourmanager toevoegen</a>
    {{>addArtistTourmanagerModal}}
{{/if}}

正如你所看到的,我在else中添加了模态,所以当我的模态更新联系人信息时,if有另一个状态。这导致模态模板在DOM即将关闭之前被排除在外。

解决方案:将模态移出if-else:

{{#if tourmanager}}
    {{>contactInformation tourmanager}}
{{else}}
    <a href="#addArtistTourmanagerModal" data-toggle="modal"><i class="fa fa-plus"></i> Tourmanager toevoegen</a>
    {{>addArtistTourmanagerModal}}
{{/if}}

其他回答

模式(’hide’)

手动隐藏模式。在modal实际被隐藏之前(即在hidden.bs.modal事件发生之前)返回给调用者。

所以与其

$('#myModal').modal('hide');
$('#someOtherSelector').trigger('click');

do

$('#myModal').modal('hide');
$('#myModal').on('hidden.bs.modal', function() {
   $('#someOtherSelector').trigger('click');
});

因此,您一定要等到“hide”事件完成。

对我来说,最好的答案是。

<body>
<!-- All other HTML -->
<div>
    ...
</div>

<!-- Modal -->
<div class="modal fade" id="myModal">
    ...
</div>

模式标记放置 始终尝试将模态的HTML代码放在文档的顶层位置,以避免其他组件影响模态的外观和/或功能。

从这个SO答案

另一个可能导致这个问题的错误,

确保你没有在页面中不止一次地包含bootstrap.js脚本!

甚至我也遇到了类似的问题,我有以下两个按钮

<button id="confirm-delete-btn" >Yes, Delete this note.</button>
<button id="confirm-delete-cancel" data-dismiss="modal">No</button>

我想执行一些ajax操作和成功的ajax操作关闭模式。这就是我所做的。

$.ajax({
        url: '/ABC/Delete/' + self.model.get("Id")
            , type: 'DELETE'
            , success: function () {                    
                setTimeout(function () {
                    self.$("#confirm-delete-cancel").trigger("click");
                }, 1200);
            }
            , error: function () {}
        });

我触发了“No”按钮的点击事件,该按钮具有data-dismiss="modal"属性。这是有效的:)

数据背景属性的初始值可以是

“静态”、“真”、“假”。

Static和true添加模态阴影,而false禁用阴影,所以你只需要在第一次点击时将这个值更改为false。是这样的:

$(文档)。(“准备好”,函数(){ var计算= 0; $ (' # id-which-triggers-modal ')。(“点击”,函数(){ 如果(数> 0){ (美元).attr(“data-backdrop”,“假”) } 数+ +; }); });