簡體   English   中英

每個 function 索引和元素

[英]each function index and element

我的問題很簡單,如何在每個 function 中使用帶有索引的元素

$('div').each(function(index, element) {
     is element equal to $(this)
});
$('div').each(function(index, element) {
     //element != $(this)
     //element == this
});

$(this) this由 jquery object 包裹的。 因此,雖然this不等於$(this) ,但您仍然可以隨心所欲地操縱它

這里有一些東西要看: http://jsfiddle.net/jomanlk/ZqXPn/

那里的element始終this相同。

js小提琴

Except wrapping it in $() will make it a jQuery object, and won't be equal to the other one, even if you wrap the other with a jQuery object.

永遠不應該有理由將其與this上下文中的element進行比較。

暫無
暫無

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

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