我正在创建拖放操作。当发生下降时,我创建了新的运行时 html 并想绑定(bind)它事件,所以我使用了以下 .on
.on ( "event", "selector", function() {
但它不起作用。这是片段:
$( "#wrap .dragImages" ).on( "click", "button.edit-new-modal", function() {
var photoId = $(this).attr('data-username');
alert(photoId);
});
.on 在拖放之前工作。但事后点击“button.edit-new-modal”没有任何反应!!怎么了?有什么解决办法吗?
最佳答案
尝试:
$(document.body).on( "click", "button.edit-new-modal", function() {
var photoId = $(this).attr('data-username');
alert(photoId);
});
关于javascript - .on 不适用于动态 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30230712/