我正在尝试在模态中显示弹出窗口,一切正常,直到我开始使用模态中的 show
事件。
只要弹出窗口打开,就会触发模式中的 show
事件,live demo here
我缺少什么?
// this will open a popover
$("#show-pop-over").on("click", function(){
var popover = "<div class='popover-content-wrapper' style='display: none;'><a href='#'>Hello ya!</a></div>";
$("body").append(popover);
$(this).popover({
html: true,
placement: "top",
title: "Title",
content: function () {
return $('.popover-content-wrapper').html();
}
}).popover("show");
});
// should fire when modal only
$("body").on("show", "#myModal", function(){
alert('modal on show event');
});
最佳答案
据我所知,弹出窗口的显示事件是从 #myModal
div 传播的,因此事件处理程序:
// should fire when modal only
$("body").on("show", "#myModal", function(){
alert('modal on show event');
});
正在正确触发。
作为解决方法,以下内容仅在显示模式时发出警报:
// should fire when modal only
$("body").on("show", "#myModal", function(e){
if ($(e.target).hasClass("modal")) {
alert('modal on show event');
}
});
关于jquery - twitter bootstrap 模态,内部有弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17149965/