这是html的代码<div id="container"> <div class="box"> <div class="img_box"><img src="img/meinv5.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv3.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv7.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv3.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv6.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv7.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv5.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv3.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv7.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv5.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv6.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv7.jpg" /></div> </div> <div class="box"> <div class="img_box"><img src="img/meinv2.jpg" /></div> </div> </div>这是js的代码window.onload=function(){ imgNum("container","box"); }function imgNum(a,b){ var anum=document.getElementById(a) var content=getbc(anum,b); console.log(content.length); }function getbc(a,b){ var barr=[]; var allcontent=a.getElementsByTagName("*"); for(var i=0;i<allcontent.length;i++){ if(allcontent[i].className==b){ barr.push(allcontent[i]); } return barr; }}实际结果
添加回答
举报
0/150
提交
取消