针对jQuery中的每个循环嵌套嵌套$(this) [英] Targeting $(this) within nested for each loops in jQuery
本文介绍了针对jQuery中的每个循环嵌套嵌套$(this)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚,在遍历一些列表项时,如何在嵌套的foreach循环中定位每个$(this)等价物。这是我的问题的一个例子:
I'm trying to figure out, when iterating through some list items, how to target each "$(this)" equivalent within nested foreach loops. Here is an example of my problem:
$('li').each(function(){
// I believe $(this) would target each li item...
$(this).children("li").each(function(){
// ... but how can I target each of these li items? Doesn't $(this) target the original loop?
});
});
推荐答案
$('li').each(function(){
var $this = $(this);
$this.children("li").each(function(){
$this; // parent li
this; // child li
});
});
这篇关于针对jQuery中的每个循环嵌套嵌套$(this)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文