当我单击“更改主题”按钮时,如何使用提供的 3 个数组更改 3 个 div 的颜色。
<script>
var colors = ['red', 'green', 'blue']
var colors1 = ['teal', 'brown', 'tan']
var colors2 = ['orange', 'purple', 'black'];
var boxed = document.querySelectorAll(".box");
var button = document.querySelector("button");
button.addEventListener("click", function () {
for (i = 0; i < boxed.length; i++) {
boxed[i].style.backgroundColor = colors[Math.floor(Math.random() * 3)];
boxed[i].style.width = '100px';
boxed[i].style.height = '100px';
boxed[i].style.display = 'inline-block';
}
});
button.style.cursor = "pointer";
</script>
慕后森
动漫人物
相关分类