将函数绑定到 Twitter Bootstrap Modal 关闭 [英] Bind a function to Twitter Bootstrap Modal Close
问题描述
我在一个新项目中使用 Twitter Bootstrap 库,我希望页面的一部分在模态关闭时刷新和检索最新的 json 数据.我在文档中的任何地方都没有看到这一点,有人可以向我指出或提出解决方案.
I am using the Twitter Bootstrap lib on a new project and I want for part of the page to refresh and retrieve the latest json data on modal close. I dont see this anywhere in the documentation can someone point it out to me or suggest a solution.
使用文档化方法的两个问题
Two problems with using the documented methods
$('#my-modal').bind('hide', function () {
// do something ...
});
我已经将隐藏"类附加到模态,因此它不会在页面加载时显示,因此会加载两次
I attach a "hide" class to the modal already so it does not display on page load so that would load twice
即使我删除了隐藏类并将元素 id 设置为 display:none
并将 console.log("THE MODAL CLOSED");
添加到上面的函数中当我关闭时什么也没有发生.
even if I remove the hide class and set the element id to display:none
and add console.log("THE MODAL CLOSED");
to the function above when I hit close nothing happens.
推荐答案
Bootstrap 3 &4
$('#myModal').on('hidden.bs.modal', function () {
// do something…
});
引导程序 3:getbootstrap.com/javascript/#modals-events
引导程序 4:getbootstrap.com/docs/4.1/components/modal/#events
$('#myModal').on('hidden', function () {
// do something…
});
参见 getbootstrap.com/2.3.2/javascript.html#modals→ 活动
这篇关于将函数绑定到 Twitter Bootstrap Modal 关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!