在html中,我有一个div标签。在此div
标签之间还有许多其他标签,如span
select
和p
标签,如下所示:
<div id="show">
<span>Span text</span>
<span>Span text</span>
<span>Span text</span>
<select id="select1">
<option>1</option>
</select>
<select id="select2">
<option>1</option>
</select>
</div>
现在我们如何发现有多少select tags
在div
id
使用jQueryid="show"
.谁能帮我找出这个。
您可以使用length
:
$('#show select').length
console.log($('#show select').length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="show">
<span>Span text</span>
<span>Span text</span>
<span>Span text</span>
<select id="select1">
<option>1</option>
</select>
<select id="select2">
<option>1</option>
</select>
</div>
选择每个select
标记,这些标记是 idshow
的div
子标记。
另外,请参阅 jquery.length
console.log($("div#show > select").length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="show">
<span>Span text</span>
<span>Span text</span>
<span>Span text</span>
<select id="select1">
<option>1</option>
</select>
<select id="select2">
<option>1</option>
</select>
</div>
这可能对您有所帮助。
$('#show select').length