Javascript 将动态加载的html类与Jquery一起使用。继续

Javascript 将动态加载的html类与Jquery一起使用。继续,javascript,jquery,html,Javascript,Jquery,Html,问题的继续 如何使用类product获取元素以获取其id?您可以使用this引用事件处理程序中的目标元素 $(".content-white").on('click', ".product", function () { var id = this.id;//this here refers to the dom element which was targeted by the handler alert(id); }); 我强烈建议阅读:“除了事件对象之外,事件处理函数还可

问题的继续


如何使用类product获取元素以获取其id?

您可以使用
this
引用事件处理程序中的目标元素

$(".content-white").on('click', ".product", function () {
    var id = this.id;//this here refers to the dom element which was targeted by the handler
    alert(id);
});

我强烈建议阅读:“除了事件对象之外,事件处理函数还可以通过关键字
this
访问处理程序绑定到的DOM元素。要将DOM元素转换为可以使用jQuery方法的jQuery对象,只需执行
$(此操作)
,通常遵循以下习惯用法:
var$this=$(this);
$(".content-white").on('click', ".product", function () {
    var id = this.id;//this here refers to the dom element which was targeted by the handler
    alert(id);
});