私がここで間違っていることを驚かす - 関数はテーブル内のすべてのセルを見て、デフォルトの背景色、フォント色、境界線の色を追加してイベントを追加するどのキーがonmousedownで押されているかによって、セルのフォーマットを変更するanonymouse関数を実行するそれぞれのリスナー。それはすべての細胞の初期のスタイリングを正しく行いますが、それだけです。匿名関数がkeydownイベントで動作しない
function setupPuzzle() {
allCells = document.querySelectorAll("table#hitoriGrid td");
for (var i = 0; i < allCells.length; i++) {
allCells[i].style.backgroundColor = "rgb(255,255,255)";
allCells[i].style.color = "rgb(0,0,0)";
allCells[i].style.borderRadius = "0px";
allCells[i].addEventListener("onmousedown", function(e) {
e.preventDefault();
if (e.shiftKey) {
allCells[i].style.backgroundColor = "rgb(255,255,255)";
allCells[i].style.color = "rgb(0,0,0)";
allCells[i].style.borderRadius = "0px";
} else if (e.altKey) {
allCells[i].style.backgroundColor = "rgb(0,0,0)";
allCells[i].style.color = "rgb(255,255,255)";
allCells[i].style.borderRadius = "0px";
} else {
allCells[i].style.backgroundColor = "rgb(101,101,101)";
allCells[i].style.color = "rgb(255,255,255)";
allCells[i].style.borderRadius = "50%";
}
});
}
}
大きな助け!それははるかに理にかなっています。 – Caelisto