[英]Array.map : get the index of each element to use in the return 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
相同。
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.