【问题标题】:How to get shown.bs.modal to trigger when the modal uses a remote URL当模态使用远程 URL 时如何让显示.bs.modal 触发
【发布时间】:2013-08-23 14:36:07
【问题描述】:

问题

当我的模态是通过传入远程 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') };

我尝试过的

我有read the docs

我尝试将我的.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 代替,这可行,但我需要元素在屏幕上可见,以便对它们执行操作。

【问题讨论】:

    标签: javascript jquery twitter-bootstrap modal-dialog


    【解决方案1】:

    从这里的拉取请求中找到了一个临时解决方案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
    

    【讨论】:

      猜你喜欢
      • 2014-07-09
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多