Bootstrap modal relatedTarget未定义 [英] Bootstrap modal relatedTarget is undefined
本文介绍了Bootstrap modal relatedTarget未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 show.bs.modal
事件的属性 relatedTarget
获取点击的元素。它总是被定义为未定义。
I am trying to get the clicked element using the property relatedTarget
of the show.bs.modal
event. It's always getting undefined though.
这就是我所拥有的:
$("#curCarSelect").on('click', function(e) {
$("#curCarModal").on('show.bs.modal', function(event) {
modalOpenedby = event.relatedTarget;
alert(modalOpenedby);
}).modal('toggle');
});
推荐答案
尝试:
$("#curCarSelect").on('click', function(e) {
$modal.modal('toggle', $(this));
});
其中$ modal是你打开的模态元素,然后:
where $modal is your modal element to open, then:
$modal.on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
})
这篇关于Bootstrap modal relatedTarget未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文