我正在尝试显示带有动态加载信息的 TwitterBootstrap 模态窗口。我想根据单击的按钮加载此信息。为此,我尝试使用 event.latedTarget() 函数,就像文档中推荐的那样。
不幸的是,这不会返回单击的按钮,因此我无法访问所需的数据类型。
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal" data-type="close_service" data-id="<?php echo $currentServices["id"]; ?>">Close Service</button>
$("#myModal").on('show.bs.modal', function (event) {
console.log("modal opening"); // This properly logs, so nothing wrong with opening
var button = $(event.relatedTarget); // Button that triggered the modal
console.log(button); // returns n.fn.init[0] with a bunch of info that has nothing to do with my button
var type = button.data('type'); // Extract info from data-* attributes
console.log(type); // returns undefined
});
感谢您的帮助。
最佳答案
也许您正在使用 bootstrap 2?在这种情况下,您必须使用: $("#myModal").on('show',...
而不是: $("#myModal").on('show.bs.modal',
参见http://getbootstrap.com/2.3.2/javascript.html#modals欲了解更多信息
关于jquery - TwitterBootstrap event.latedTarget() 不返回单击的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159404/