テーブルを反復処理する方法について以前の回答を見てきましたが、それを機能させることができません。私は愚かなことをしているに違いない。次に例を示します。
私はCSSでこれを持っています
td{width: 30px; height: 30px;
}
<body onload = "setBackground();">
<table id = "table1">
<tr id = "row1">
<td>Stack</td>
<td>Overflow</td>
<td>Is my life saver</td>
</tr>
</table>
</body>
今、JSで私はこれを持っています
function setBackground() {
var table = document.getElementById("table1");
//i found this in a previous stack overflow answer and tried it
for (var i = 0, row; row = table.rows[i]; i++) {
for (var j = 0, col; col = row.cells[j]; j++) {
//this is for debugging purposes... I can't even get this to work
alert(table.rows[i].cells[j]);
table.rows[i].cells[j].style.background = "orange"; //just an example
}
}
}
body タグで関数を呼び出していることに注意してください。これは機能していません。私はこれを理解しようとしてきましたが、できません! また、私はJQueryを知りません。誰かが親切に私を助けることができれば、私はそれを感謝します.