我想调用 all div
s 因为TUTTIiDIV
它已经是一个数组。当我运行此代码时,控制台看起来不错,但代码无法按预期工作。
如何选择数组的所有元素TUTTIiDIV
?
document.addEventListener("DOMContentLoaded", function() {
var TUTTIiDIV = document.querySelectorAll("div");
document TUTTIiDIV.onclick = function() {
coloraicontorni()
}
}); //END DOMcontentLoaded
function coloraicontorni() {
var TUTTIiDIV = document.querySelectorAll("div");
for (i = 0; i <= TUTTIiDIV.length; i++) {
TUTTIiDIV[i].classList.add('contorno');
}
};
* {
box-sizing: border-box;
}
body {
background-color: antiquewhite;
}
#rosso {
width: 25%;
height: 150px;
background-color: red;
display: inline-block;
}
#blu {
width: 25%;
height: 150px;
background-color: blue;
display: inline-block;
}
#giallo {
width: 25%;
height: 150px;
background-color: yellow;
display: inline-block;
}
.contorno {
border: 8px solid black;
}
<div id="rosso"></div>
<div id="blu"></div>
<div id="giallo"></div>
慕尼黑8549860
相关分类