jquery – Bootstrap Popover,.click没有捕捉到popover内的按钮

首先,问题的小提琴: jsfiddle.net

我正在使用popover,它的内容是html,一个类“click_me”的按钮。我有jquery听点击“click_me”,它应该发出警报。但是,它没有。我错过了什么吗?

JS:

jQuery(document).ready(function($) {

$('.demo_button').click(function () {
    $(this).popover({
                html: true,trigger: 'manual',placement: 'right',content: function () {
                    var $buttons = $('#popover_template').html();
                    return $buttons;
                }
    }).popover('toggle');
});

$('.click_me').click(function() {
    alert('it works!');
});

});

HTML:

<button class="btn btn-primary demo_button">Click here</button>

<div id="popover_template">
    <button class="btn click_me">Make Alert</button>
</div>

解决方法

.click()只适用于您需要使用on的加载元素()
$(document).on("click",".click_me",function() {
    alert('it works!');
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...