JS如何获取某个div下存在多少个子div
1个回答
展开全部
<script>
window.onload = function () {
var myDiv = document.getElementById("myDiv");
var div_s = myDiv.getElementsByTagName("div");
alert(div_s.length);
}
</script>
<body>
<div id="myDiv" >
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</body>
window.onload = function () {
var myDiv = document.getElementById("myDiv");
var div_s = myDiv.getElementsByTagName("div");
alert(div_s.length);
}
</script>
<body>
<div id="myDiv" >
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</body>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询