js中HTMLCollection如何循环
//不带索引
let divCon = document.getElementsByClassName("el-form-item__error");
if (divCon.length > 0) {
for (var item of divCon) {
console.log("打印:", item.innerText);
}
}
//带有索引
let divCon = document.getElementsByClassName("el-form-item__error");
if (divCon.length > 0) {
for (var i = 0; i < divCon.length; i++) {
console.log("11", divCon[i].innerText); i是索引值
}
}