只是想知道是否有人可以查看这段代码并让我知道我是否正确。尝试遍历 allCells 对象集合并将背景颜色设置为白色并运行一个事件处理程序,该处理程序在单击每个单元格时运行 changeColor() 函数。谢谢!
window.onload = setPuzzle;
var allCells;
function setPuzzle() {
var puzzleTable = document.getElementById("puzzleCells");
var allCells = document.getElementsByName("puzzleTable");
for (var i = 0; i < allCells.length; i++) {
allCells[i].style.backgroundcolor = "white";
}
for (var i = 0; i < allCells.length; i++) {
allCells[i].onclick = changeColor()
}
document.getElementById("solution").onclick = showSolution();
document.getElementById("hide").onclick = hideSolution();
document.getElementById("check").onclick = checkSolution();
document.getElementById("uncheck").onclick = uncheckSolution();
}