js如何获取固定id下的相同class的长度?求大神指教 5
代码如下,如何获取固定id下的相同class的长度?应该用原生js怎么写啊?<divid="sss"><divclass="a">qq</div><divclass="a...
代码如下,如何获取固定id下的相同class的长度?应该用原生js怎么写啊?
<div id="sss">
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
</div> 展开
<div id="sss">
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
<div class="a">qq</div>
</div> 展开
1个回答
2015-07-23
展开全部
var pdiv = document.getElementById("sss");
var childs = pdiv.children;
var classCount = 0;
for(var i = 0 ; i< childs.length; i++){
if(childs[i].className == 'a'){
classCount ++;
}
}
alert(classCount);
var childs = pdiv.children;
var classCount = 0;
for(var i = 0 ; i< childs.length; i++){
if(childs[i].className == 'a'){
classCount ++;
}
}
alert(classCount);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询