Jquery 循环内的目标?
Jquery 循环内的目标?,jquery,Jquery,.question是一个li,在中。questionli是另一个列表,其中包含class。answers,每个列表都包含class的li。answer 我尝试过在上述循环中以他们为目标,但没有成功: $("#questions .question").each(function() {} 是否有人知道如何使用此选项定位循环中的每个答案li?$(this)。查找('.answer')或('.answer',this) 它们是等价的。来自jQuery来源: $(this).$(".answer")
.question
是一个li,在中。question
li是另一个列表,其中包含class。answers
,每个列表都包含class的li。answer
我尝试过在上述循环中以他们为目标,但没有成功:
$("#questions .question").each(function() {}
是否有人知道如何使用此选项定位循环中的每个答案li?$(this)。查找('.answer')
或('.answer',this)
它们是等价的。来自jQuery来源:
$(this).$(".answer").each(function() {}
$(this).查找('.answer')
或$('.answer',this)
它们是等价的。来自jQuery来源:
$(this).$(".answer").each(function() {}
使用$(此)
:
使用$(此)
:
您可以传递要应用选择器的上下文。在这种情况下,通过
此将实现您想要的:
$("#questions .question").each(function() {
$(this).find(".answer").each( function() {
//code here
} );
}
您可以传递要应用选择器的上下文。在这种情况下,通过此将实现您想要的:
$("#questions .question").each(function() {
$(this).find(".answer").each( function() {
//code here
} );
}
$("#questions .question").each(function() {
$(".answer", this).each(function() { // Pass `this` as the context
});
}
$("#questions .question").each(function(index, element) {
$(element).find('.answer').each(function(index, element) {
/* do stuff */
});
});