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

我该怎么办?


当前回答

这行代码在许多搜索后解决了我的问题,我想关闭ajax成功的模式:

$('#exampleModal').modal('hide');
$("[data-dismiss=modal]").trigger({ type: "click" });

非常感谢,曼纽尔·费尔南多 https://stackoverflow.com/a/27218322/5935763

其他回答

在动作按钮中插入:

data-backdrop="false"

and

data-dismiss="modal" 

例子:

<button type="button" class="btn btn-default" data-dismiss="modal">Done</button>

<button type="button" class="btn btn-danger danger" data-dismiss="modal" data-backdrop="false">Action</button>

如果你输入这个data-attr, .modal- background将不会出现。 关于它的文档在这个链接:http://getbootstrap.com/javascript/#modals-usage

供你参考,如果有人遇到这种情况……我花了大约3个小时发现最好的方法如下:

$("#my-modal").modal("hide");
$("#my-modal").hide();
$('.modal-backdrop').hide();
$("body").removeClass("modal-open");

关闭模态的函数非常不直观。

我也有同样的问题。我发现这是由于Bootstrap和JQueryUI之间的冲突。

两者都使用“close”类。改变其中一个类可以解决这个问题。

使用切换而不是隐藏,解决了我的问题

在应用了最高评级的解决方案后,我有一个问题,它打破了将来情态动词正确打开。我已经找到了我的解决方法

        element.on("shown.bs.modal", function () {
            if ($(".modal-backdrop").length > 1) {
                $(".modal-backdrop").not(':first').remove();
            }
            element.css('display', 'block');
        });