twitter-bootstrap 在 Bootstrap Modal 上捕获关闭事件

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

Capture close event on Bootstrap Modal

twitter-bootstrapeventsbootstrap-modal

提问by cfnerd

I have a Bootstrap Modal to select events. If the user clicks on the X button or outside the modal, I would like to send them to the default event. How can I capture these events?

我有一个 Bootstrap Modal 来选择事件。如果用户点击 X 按钮或模式之外,我想将它们发送到默认事件。如何捕捉这些事件?

This is my HTML code:

这是我的 HTML 代码:

<div class="modal" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content event-selector">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                <center><h1 class="modal-title event-selector-text">Select an Event</h1><center>
            </div>
            <div class="container"></div>
            <div class="modal-body">
                <div class="event-banner">
                    <a href="/?event=1">
                        <img src="<?php echo IMAGES_EVENT1_LOGO; ?>" width="100%">
                    </a>
                </div>
                <div class="event-banner">
                    <a href="/?event=2">
                        <img src="<?php echo IMAGES_EVENT2_LOGO; ?>" width="100%">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

回答by cfnerd

This is very similar to another stackoverflow article, Bind a function to Twitter Bootstrap Modal Close. Assuming you are using some version of Bootstap v3 or v4, you can do something like the following:

这与 stackoverflow 的另一篇文章Bind a function to Twitter Bootstrap Modal Close非常相似。假设您使用的是 Bootstap v3 或 v4 的某个版本,您可以执行以下操作:

$("#myModal").on("hidden.bs.modal", function () {
    // put your default event here
});

回答by vibs2006

Though is answered in another stack overflow question Bind a function to Twitter Bootstrap Modal Closebut for visual feel here is more detailed answer.

虽然在另一个堆栈溢出问题Bind a function to Twitter Bootstrap Modal Close 中得到了回答,但为了视觉感受,这里有更详细的答案。

Source: http://getbootstrap.com/javascript/#modals-events

来源:http: //getbootstrap.com/javascript/#modals-events

回答by Eduardo Sganzerla

I tried using it and didn't work, guess it's just the modal versioin.

我尝试使用它但没有用,猜测它只是模态版本。

Although, it worked as this:

虽然,它是这样工作的:

$("#myModal").on("hide.bs.modal", function () {
    // put your default event here
});

Just to update the answer =)

只是为了更新答案=)