Bootstrap popovers不允许DOM访问。该怎么办?

时间:2015-06-01 18:26:48

标签: javascript jquery twitter-bootstrap

我遇到Bootstrap(3.3.4)弹出窗口问题。我的popover的html代码位于data-html标记中,该标记还包含一个类link_click。这个类的jQuery单击函数不起作用。为什么jQuery没有从popover的数据内容字段中看到这个link_click类?要改变什么?

popover = '<a href="javascript:void(0)" data-toggle="popover" data-placement="bottom" data-html="true" data-content="<a href=\'javascript:void(0)\' class=\'link_click\'>Popover Link not working</a><br>">Main-Objekt</a>';

$('#popover_test').html( popover );

$('[data-toggle="popover"]').popover({ trigger:"manual", animation:false})
.on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function () {
    $(_this).popover('hide');
});})
.on("mouseleave", function () {
var _this = this;
setTimeout(function () {
    if (!$(".popover:hover").length) {
        $(_this).popover("hide");
    }
}, 100);
}); 

$('.link_click').click( function(){
    alert('Click success!');
}); 

由于

迈克尔

1 个答案:

答案 0 :(得分:0)

动态内容的事件委派:

$('#popover_test').on('click', '.link_click', function(){
    alert('Click success!');
});