如何处理Twitter Bootstrap中的模式关闭事件? [英] How to handle the modal closing event in Twitter Bootstrap?

查看:69
本文介绍了如何处理Twitter Bootstrap中的模式关闭事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Twitter引导程序中,查看模态文档.我无法弄清楚是否有办法监听模态的close事件并执行函数.

In Twitter bootstrap, looking at the modals documentation. I wasn't able to figure out if there is a way to listen to the close event of the modal and execute a function.

例如让我们以这种模式为例:

e.g. lets take this modal as an example:

<div class="modal-header">
    <button type="button" class="close close_link" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Modal header</h3>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
    <a href="#" class="btn close_link" data-dismiss="modal">Close</a>   
</div>

由于data-dismiss="modal",顶部的X按钮和底部的关闭按钮都可以隐藏/关闭模态.所以我想知道,是否可以听一下?

The X button on top and the close button on bottom can both hide/close the modal because of data-dismiss="modal". So I wonder, if I could somehow listen to that?

或者,我想可以像这样手动进行...

Alternatively I could do it manually like this, I guess...

$("#salesitems_modal").load(url, data, function() { 
     $(this).modal('show'); 
     $(this).find(".close_link").click(modal_closing);
});

您怎么看?

推荐答案

已针对Bootstrap 3和4更新

Bootstrap 3

Updated for Bootstrap 3 and 4

Bootstrap 3 and Bootstrap 4 docs refer two events you can use.

hide.bs.modal :调用hide实例方法后,立即触发此事件.
hidden.bs.modal :当该模式已完全向用户隐藏时将触发此事件(将等待CSS转换完成)​​.

hide.bs.modal: This event is fired immediately when the hide instance method has been called.
hidden.bs.modal: This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).

并提供有关如何使用它们的示例:

And provide an example on how to use them:

$('#myModal').on('hidden.bs.modal', function () {
  // do something…
})

旧版Bootstrap 2.3.2答案

Bootstrap的文档引用了两个可以使用的事件.

Legacy Bootstrap 2.3.2 answer

Bootstrap's documentation refers two events you can use.

隐藏:调用hide实例方法后,立即触发此事件.
隐藏:此模式在向用户隐藏完模式后将触发此事件(将等待CSS转换完成)​​.

hide: This event is fired immediately when the hide instance method has been called.
hidden: This event is fired when the modal has finished being hidden from the user (will wait for css transitions to complete).

并提供了有关如何使用它们的示例:

And provides an example on how to use them:

$('#myModal').on('hidden', function () {
    // do something…
})

这篇关于如何处理Twitter Bootstrap中的模式关闭事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆