我知道下面的代码是不敛元素的最有效的方式,但是对于一个例子的缘故...如何在jquery中访问“THIS”的不同级别?
$('.myFirstClass').each(function(i){
// Here is the first 'THIS' occurrence
$(this).find('.mySecondClass').each(function(j){
// Here is the second 'THIS' occurrence
// How do i access the first occurrence from here?
});
});
`var firstClassThis = this;`是多余的。 jQuery已经管理这些标识符。看到我的答案。 – Sampson 2009-07-30 16:49:37
如果你已经在使用索引,你的代码看起来更好。如果我不关心索引,我可能会在局部变量中捕获“this”。 – SolutionYogi 2009-07-30 16:52:28
确实如此。 +1 – Sampson 2009-07-30 19:08:01