twitter bootstrap模式与popover里面

时间:2013-06-17 14:26:48

标签: jquery twitter-bootstrap modal-dialog popover

我试图在模态中显示一个弹出窗口,一切都很有效,直到我开始使用模态的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');
});

1 个答案:

答案 0 :(得分:1)

据我所知,popover的show事件是从#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');
    }
});
相关问题