簡體   English   中英

如何將$(this)設置為clicked元素

[英]How to set $(this) as the clicked element

在下面的代碼中:

// submit an item
$(document).on("click", ".match-item", function(event) {


    // how to set $(this) == $('.match-item') clicked?

});

我正在尋找檢索$(this)作為單擊項,而不是document本身。 我該怎么做?

這更多是澄清而不是答案。

this已經指的是當前單擊的元素。

 $(document).on("click", ".match-item", function(event) { console.log($(this).attr('class')); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="parent"> Parent <div class="match-item">----Click Me</div> </div> 

怎么樣

$('.match-item').click(function() {
     //your code with $(this) here
});

我很確定$(this)將引用類match-item的元素

暫無
暫無

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

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