内容简介:http://stackoverflow.com/questions/23891478/bootstrap-modal-dialog-show-bs-modal-event-relatedtarget-is-undefined-how-can
按钮调用模态对话框:当单击按钮时,事件触发生成的事件引用e.relatedTarget未定义.那么,如何从处理程序中获取调用按钮? e似乎没有包含对调用按钮的引用.
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
jQuery的:
$('#myModal').on('show.bs.modal', function (e) {
console.log(e.relatedTarget) // do something...
})
看看下面的 Bootply example
.
当运行show事件似乎包括对e.relatedTarget的适当引用.
$('#myModal').on('show.bs.modal', function (e) {
var button = e.relatedTarget;
if (button != null)
{
alert("Launch Button ID='" + button.id + "'");
}
})
看看 Bootply example ,看看你自己的代码是否偏离了它. (我从您提供的 link 直接复制了原始的Bootstrap示例代码片段.)
我希望这有帮助.祝你好运.
http://stackoverflow.com/questions/23891478/bootstrap-modal-dialog-show-bs-modal-event-relatedtarget-is-undefined-how-can
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 使用React手写一个对话框或模态框
- 使用HTML5原生对话框元素,轻松创建模态框组件
- Android进度对话框
- 使用导航组件: 对话框目的地
- VBScript - 弹出“文件选择对话框”方法大全!
- jQuery实现定时隐藏对话框的方法分析
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JavaScript设计模式
Ross Harmes、Dustin Diaz / 谢廷晟 / 人民邮电出版社 / 2008 / 45.00元
本书共有两部分。第一部分给出了实现具体设计模式所需要的面向对象特性的基础知识,主要包括接口、封装和信息隐藏、继承、单体模式等内容。第二部分则专注于各种具体的设计模式及其在JavaScript语言中的应用,主要介绍了工厂模式、桥接模式、组合模式、门面模式等几种常见的模式。为了让每一章中的示例都尽可能地贴近实际应用,书中同时列举了一些JavaScript 程序员最常见的任务,然后运用设计模式使其解决方......一起来看看 《JavaScript设计模式》 这本书的介绍吧!