就像是://Hide all divsfor(let i=0;i<document.querySelectorAll(".add_icon").length;i++){ document.querySelectorAll(".add_icon")[i].style.display = "none";}//Go back and show the very first onedocument.querySelector(".add_icon").style.display = "block";这将隐藏所有带有 .add_icon 类的 div,然后返回并显示第一个。您提到想要计数,所以如果您想将其用于某些用途,您可以这样做:let divCount = document.querySelectorAll(".add_icon").length;
let divs = document.getElementsByClassName('add_icon'); for(let i = 0; i < divs.length; i++){ //Display the first div and hide the rest if(i == 0) divs[i].style.display = 'block'; else divs[i].style.display = 'none'; }