簡體   English   中英

使用Jquery動態加載的html類。 繼續

[英]Use classes of dynamically loaded html with Jquery. Continue

繼續問題使用Jquery動態加載的html類

$(".content-white").on('click', ".product", function () {
    var id = $(".product").attr('id');
    alert(id);
});

我怎樣才能獲得一個帶有類產品的元素來獲取它的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);
});

在事件處理功能內部

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM