[英]How to catch event when user clicks outside of bootstrap modal dialog?
Scenario :场景:
Problem :问题:
When user clicks on the close button or the "X" in the corner I catch this event by assigning a class to these two elements and assigning an event to this class.当用户单击关闭按钮或角落的“X”时,我通过将 class 分配给这两个元素并将事件分配给该 class 来捕获此事件。
Code :代码:
$(document).on("click", ".dialogTankClose", function() {
//some code
})
My problem is that i can't figure out how to catch when the user clicks outside of the dialog or presses "escape".我的问题是当用户在对话框外单击或按“转义”时,我无法弄清楚如何捕捉。
$(document).on("click", "modalCloseEvent",function(){
// how to catch this?
})
How can I catch this?我怎么能抓住这个?
The Bootstrap modal raises an event when it closes, which you can hook to: hidden.bs.modal
. Bootstrap模态在关闭时会引发一个事件,您可以将其挂钩到:
hidden.bs.modal
。 This event fires no matter how the modal is closed. 无论如何关闭模式,都会触发此事件。 Try this:
尝试这个:
$('#bootstrapModal').on("hidden.bs.modal", function() {
$.automation.worker.bindIntervalEvent("#TanksContent", "/Tank/GetTanks", function () {
$.automation.tanks.tableInit();
});
});
You can use a delegated event handler if the modal is dynamically added to the DOM: 如果将模式动态添加到DOM,则可以使用委托事件处理程序:
$(document).on("hidden.bs.modal", '#bootstrapModal', function() {
$.automation.worker.bindIntervalEvent("#TanksContent", "/Tank/GetTanks", function () {
$.automation.tanks.tableInit();
});
});
More information in the Bootstrap documentation Bootstrap文档中的更多信息
You can use 'hidden.bs.modal' modal method to run custom code while modal is getting unload / hide from document.您可以使用“hidden.bs.modal”模态方法在模态从文档中卸载/隐藏时运行自定义代码。
$('#your-modal-ID').on('hidden.bs.modal', function (e) {
console.log("Hey !! I am unloading... ");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.