twitter-bootstrap – 引导模态对话框,show.bs.modal事件relatedTarget未定义.如何获得点击元素?

栏目: CSS · 发布时间: 7年前

内容简介: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...
})

参考: http://getbootstrap.com/javascript/#modals

看看下面的 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


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

点击的奥秘:运用说服心理术提升在线影响力(全彩)

点击的奥秘:运用说服心理术提升在线影响力(全彩)

Nathalie Nahai(娜塔莉.纳海) / 陈旭 / 电子工业出版社 / 2014-9-1 / 75.00元

用户的每一次点击,不管是在虚拟商店购物,还是在浏览企业网站,或是漫无目的地把玩手机,都蕴藏着基于心理学的无穷奥秘。《点击的奥秘:运用说服心理术提升在线影响力》作者为全球知名的网络心理学家,其在《点击的奥秘:运用说服心理术提升在线影响力》中将心理学、神经科学及行为经济学巧妙地结合在一起,挖掘和提炼出一套行之有效的网络用户引导策略——既涵盖在线说服最新研究动向,也包括最前沿的科技成果,以及其他诸多惊人......一起来看看 《点击的奥秘:运用说服心理术提升在线影响力(全彩)》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具