使用 AJAX 关闭 Bootstrap 的模态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19596734/
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-09-06 11:07:50  来源:igfitidea点击:

Close Bootstrap's modal with AJAX

ajaxtwitter-bootstrap

提问by Jon

I use the modal of Twitter's Bootstrap.You can close the modal, by clicking on a button or something different with the tag data-dismiss="modal". I would like to process my form in the modal with AJAX (by clicking on a submit button) and then close the modal. So how do close this modal in AJAX? Or is that not possible?

我使用Twitter 的 Bootstrap 模式。您可以通过单击按钮或带有标签的不同内容来关闭模式data-dismiss="modal"。我想使用 AJAX 在模式中处理我的表单(通过单击提交按钮),然后关闭模式。那么如何在 AJAX 中关闭这个模态呢?或者那是不可能的?

(sorry for my bad English...)

(对不起,我的英语不好...)

回答by Joseph

If you read further down the documentation:

如果您进一步阅读文档:

$('#myModal').modal('hide')

Just get the ID of the modal, and replace myModalwith it. Then place it in the AJAX success handler and there you have it.

只需获取模态的 ID,并myModal用它替换即可。然后将它放在 AJAX 成功处理程序中,您就拥有了它。

回答by David Arul

You can use this script to close the modal

您可以使用此脚本关闭模态

<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">
    <i class = "icons-office-52"></i> 
</button> 
    $("#close_btn").trigger("click");

or

或者

$('#my_model').modal('hide');