js怎么根据蒜素的下标查询该元素
展开全部
<div id="main" class=“main">
<div class=“child"></div>
<div class=“child"></div>
<div class=“child"></div>
<div class=“child"></div>
</div>window.onload = function () {
var main = document.getElementById("main");
var divs = main.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
divs[i].indexs = i;
}
}
<div class=“child"></div>
<div class=“child"></div>
<div class=“child"></div>
<div class=“child"></div>
</div>window.onload = function () {
var main = document.getElementById("main");
var divs = main.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
divs[i].indexs = i;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询