在Twitter bootstrap中,查看modals文档 . 我无法弄清楚是否有办法收听模态的关闭事件并执行一个函数 .
例如我们以此模态为例:
<div class="modal-header">
<button type="button" class="close close_link" data-dismiss="modal" aria-hidden="true">×</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按钮和底部的关闭按钮都可以隐藏/关闭模态 . 所以我想知道,如果我能以某种方式听那个?
或者我可以像这样手动做,我猜...
$("#salesitems_modal").load(url, data, function() {
$(this).modal('show');
$(this).find(".close_link").click(modal_closing);
});
你怎么看?
3 回答
已更新为Bootstrap 3和4
Bootstrap 3和Bootstrap 4 docs引用您可以使用的两个事件 .
并提供如何使用它们的示例:
Legacy Bootstrap 2.3.2答案
Bootstrap's documentation指的是您可以使用的两个事件 .
并提供了如何使用它们的示例:
如果动态添加模态div,则使用(For bootstrap 3)
这也适用于非动态内容 .
有两对模态事件,一个是“显示”和“显示”,另一个是“隐藏”和“隐藏” . 从名称中可以看出,当模态即将结束时隐藏事件触发,例如单击右上角的十字或关闭按钮等 . 虽然隐藏在模态实际关闭后被触发 . 你可以自己测试这些事件 . 例如:
而且,至于你的问题,我认为你应该听你的模态的'隐藏'事件 .