当页面呈现时存在类时,以下代码有效:
$().ready(function () {
$(".productzoom").on('hover click', function () {//also add this function to click
$(this).closest(".product1").find(".image span").css('top', $(this).position().top - 200);
$(this).closest(".product1").find(".image span").css('left', $(this).position().left + 20);
});
});
但是,后来我动态插入内容,当我将鼠标悬停或单击 .productzoom 类时,上面的代码似乎不再起作用。我认为通过使用 .on jQuery 会将钩子也附加到新插入的元素上,但它没有......为什么?