当模式使用远程URL时,如何使shown.bs.modal触发

How to get shown.bs.modal to trigger when the modal uses a remote URL

本文关键字:何使 shown bs 触发 modal 模式 URL      更新时间:2023-09-26

问题

当通过传入远程url生成模态时,我无法使shown.bs.modal正确激发。

在以下代码中,hidden.bs.modal始终有效。

守则

$('#my_modal').on("shown.bs.modal", set_up_modal);
$('#my_modal').on("hidden.bs.modal", tear_down_modal);
$('#my_modal').modal({ remote: target_url  });
set_up_modal    = function() { console.log('up') };
tear_down_modal = function() { console.log('down') };

我尝试过的

我已经看过文件了。

我曾尝试将我的.on更改为读起来更像$('body').on("shown.bs.modal", '#my_modal', saa.set_up_modal);,但这没有产生任何更改(hidden.bs.modal再次起作用)。

更新

我已经添加了console.log($._data( $('#my_modal')[0], "events" ));,可以确认shown正在绑定到对象,只是没有被调用。

我尝试过使用show.bs.modal,这很有效,但我需要元素在屏幕上可见,以便对它们进行处理。

在此处从拉取请求中找到临时解决方案https://github.com/twbs/bootstrap/commit/4b1a6e11326fee97a5ebc194be040086f40f97fb

根据下面的内容编辑modal.js文件的第81行已经为我解决了这个问题,直到做出请求

-        that.$element.find('.modal-dialog') // wait for modal to slide in
+        that.$element // wait for modal to slide in