首先,问题的小提琴:
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!');
});