如何识别打开引导模式的元素?

时间:2013-09-07 14:33:27

标签: twitter-bootstrap

我有三个元素使用bootstrap模式打开相同的模态对话框。我想知道是否有办法知道哪个元素在shown事件上打开了模态

$('#myModal').on("shown.bs.modal", function () {
    //get the element that opened the modal
    //console.log(event.target.id);
});

有可能吗?如果是这样,怎么样?

小提琴:http://jsfiddle.net/codovations/S9Bp4/2/

1 个答案:

答案 0 :(得分:2)

event.relatedTarget为我工作。为可能偶然发现同一问题的人提供此服务

$('#myModal').on("shown.bs.modal", function (evt) {
    //get the element that opened the modal
    console.log(evt.relatedTarget);
});

小提琴:http://jsfiddle.net/codovations/S9Bp4/3/

相关问题