我正在使用Twitter引导模态对话框。当我点击引导模式对话框的提交按钮时,它会发送一个AJAX请求。我的问题是情态背景并没有消失。模态对话框确实消失了,但是“模态背景”在屏幕上创建的不透明度仍然存在
我该怎么办?
我正在使用Twitter引导模态对话框。当我点击引导模式对话框的提交按钮时,它会发送一个AJAX请求。我的问题是情态背景并没有消失。模态对话框确实消失了,但是“模态背景”在屏幕上创建的不透明度仍然存在
我该怎么办?
当前回答
在考虑了所有的答案之后,我想出了一个包罗万象的解决方案。 最终,这是唯一对我有用的方法。 (香草javascript):
var elem = document.querySelectorAll('[data-dismiss="modal"]')[0];
var evt = new Event('click');
elem.dispatchEvent(evt);
var modalelem = document.getElementById('exampleModalCenter');
var myModal = new bootstrap.Modal(modalelem, { keyboard: false })
const fade = modalelem.classList.contains('fade');
if (fade) {
modalelem.classList.remove('fade');
}
myModal.hide();
myModal.dispose();
var backdrop = document.getElementsByClassName('modal-backdrop')[0];
backdrop.style.display = 'none';
var modalopen = document.getElementsByClassName('modal-open')[0];
modalopen.classList.remove('modal-open');
modalopen.style.removeProperty("overflow");\
其他回答
updatepanel issue。
我的问题是由于更新面板的位置。我在更新面板上有整个模式。如果你在更新面板之外声明了模态在更新面板中只有模态主体,那么 $ (' # myModalID ') .modal(隐藏的); 工作。
我知道这是一个非常老的帖子,但这可能会有所帮助。 这是我的一个非常小的解决办法
$('#myModal').trigger('click');
就是这样,这应该能解决问题
use:
$('.modal.in').modal('hide')
源
有些情况下,其他答案(有帮助的和有效的)不能很容易地应用。那么,一个可能的解决方案是实现一个事件,在模态对话框消失后不久触发对模态背景的单击。
下面是一个基于以下模态对话框的例子:
<div class="modal fade ..." id="IdOfMyModal" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
...
</div>
要在点击模态时删除“modal- background in”(在屏幕上创建背景不透明),添加以下代码:
$('#IdOfMyModal').on("click", function() {
setTimeout(function() {
if ($('#IdOfMyModal').css("opacity") != "1")
$('.modal-backdrop').trigger('click');
}, 100);
});
在模式中的任何按钮上添加data-dismiss="modal"对我来说都很有效。我想让我的按钮调用angular函数来触发ajax调用并关闭模态,所以我在函数中添加了.toggle(),它工作得很好。(在我的情况下,我使用了一个bootstrap模态和使用一些角,而不是一个实际的模态控制器)。
<button type="button" class="btn btn-primary" data-dismiss="modal"
ng-click="functionName()"> Do Something </button>
$scope.functionName = function () {
angular.element('#modalId').toggle();
$.ajax({ ajax call })
}