下面的代碼通過AJAX將數據添加到所述容器#section:.on()處理程序不能處理用.html()創建的元素,爲什麼?
$(".btnGetImages").click(function(event){
event.preventDefault();
// get id of article
var id = $(this).attr('data-id');
// get images via ajax
$.ajax({
url: "includes/get_images.php",
type: "get",
data: {article:id},
success: function(data) {
// insert data into container
$("#section").html(data);
},
error:function() {
$("#section").html('show error msg here...');
}
});
});
裏面的容器#section有與類.thumb,我想點擊元素。出於某種原因,點擊不會觸發,即使我正確添加.on事件。爲什麼?
$(".thumb").on("click", function(event) {
alert('yo, im a thumb...');
event.preventDefault();
});
事件代表團..... – lifetimes
@null:我讀過關於代表團,但它說代表()已被.on()方法取代... – Marco
所以你讀過關於如何使用'on ()'?顯然不是,因爲那不是你寫的。 – Barmar