HTML
<div id="t">
<input type="button" class="theClass" />
<input type="button" class="theClass" />
<input type="button" class="notTheClass" />
</div>
Javascript
var result = $('#t > input').find('.theClass').length;
console.log(result);
预期结果:2
实际结果:0
JSFiddle:here .
Get the descendants of each element in the current set of matched elements, filtered by a selector
有人能解释一下为什么 .find()
过滤掉所有元素而不是只返回我正在搜索的 2 个元素吗?
边注:
$('#t > input').length
正确返回:3
最佳答案
为什么要使用 find ?什么时候可以做到这一点。
var result = $('#t > input.theClass').length;
关于javascript - jQuery .find 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19120936/