[英]Javascript method wont work with dynamic elements
Okay so if this was to do with a click event i would know to do something like ... 好吧,如果这与点击事件有关,我想做类似...
$('body').on('click','.element',function(){
....do something
});
But the code i have here is: 但是我在这里的代码是:
$('.checkout .popbtn').popover({
trigger: 'manual',
html: true,
container: 'body',
placement: 'bottom',
animation: false,
content: function(){
return $('#popover').html();
}
});
.popbtn is the dynamically generated element. .popbtn是动态生成的元素。
How can i get around this? 我该如何解决?
Thanks 谢谢
当您的按钮添加到页面后,调用您的code
。
使用DOMNodeInserted获取在页面上创建元素的时间
$('body').on('DOMNodeInserted', '.popbtn', function () { $('.checkout .popbtn').popover({ trigger: 'manual', html: true, container: 'body', placement: 'bottom', animation: false, content: function(){ return $('#popover').html(); } }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.