I'm using modal dialog with remote option:

我正在使用带远程选项的模态对话框:

<a target="profile-banner" data-target="#edit-slide-dlg" href="/Banner/SlideEditModal/1/1"
data-toggle="modal" class="banner-slide-control">Edit</a>

Where:

<div id="edit-slide-dlg" class="modal fade" tabindex="-1"></div>

Also, I'm listening for shown.bs.modal event where I use event.target property:

另外,我正在监听使用event.target属性的shown.bs.modal事件:

$("body").on("shown.bs.modal", function (event) {
  // do something with event.target 
}

Some reason this event is not fired when I open dialog for the first time. And it gets fired for the second time only. I tried to browse bootstrap scripts and found this code (see my comment):

我第一次打开对话框时没有触发此事件的原因。它只是第二次被解雇了。我试图浏览bootstrap脚本并找到此代码(请参阅我的评论):

var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
transition ?
that.$element.find('.modal-dialog') // wait for modal to slide in
   .one($.support.transition.end, function () {
      that.$element.focus().trigger(e) //THIS LINE NEVER EXECUTED AT FIRST DIALOG OPENING
   })
   .emulateTransitionEnd(300) :
that.$element.focus().trigger(e)

So, I turned off transition as a workaround, It made event be fired for the first time, but, event.target is empty string. For the second time event.target contains appropriate dialog HTML. Is this problem with my code or bootstrap?

所以,我关闭了转换作为一种解决方法,它使事件第一次被触发,但是,event.target是空字符串。第二次,event.target包含适当的对话框HTML。这是我的代码或引导程序的问题?

1 个解决方案

#1


5

I had the exact same Problem. I could fix it with the solution to this StackOverflow question: Bootstrap modal 'loaded' event on remote fragment

我有同样的问题。我可以解决这个StackOverflow问题的解决方案:在远程片段上启动模态'已加载'事件

Basically you have to open the modal manually and implement the Ajax loading yourself. Something like:

基本上你必须手动打开模态并自己实现Ajax加载。就像是:

$modal.modal({
    'show': true
}).load('/Banner/SlideEditModal/1/1', function (e) {
    // this is executed when the content has loaded.
});

更多相关文章

  1. 更改html隐藏字段的事件
  2. 当AJAX响应来自PHP文件时,如何显示以消息为中心的加载器图像&防止
  3. 为什么使用observe_field代码不能使用JQuery模型对话框?
  4. JQuery 总结(3) jQuery 各种事件
  5. jQuery UI对话框调整大小关闭按钮
  6. jQuery 选择器 与 事件
  7. jquery不会对select/选项更改事件作出反应。
  8. 使用HTML5验证时如何绑定到提交事件?
  9. 最简单jquery.ajax+php例子(对话框显示文本框输入内容),以小见大

随机推荐

  1. BitmapFactory.Options学习笔记
  2. Android的Context简介
  3. Android中的一些开关
  4. Android Studio之安卓学习布局管理器
  5. [android]控件Button常用属性
  6. Android(安卓)NIO简易聊天室
  7. android属性
  8. Android经典三部曲:
  9. Android OpenGL开发目录
  10. Android(安卓)线性布局(LinearLayout)相关