我正在尝试将“takenappt”数组中找到的表格单元格的背景颜色更改为黑色,而不是默认的白色。这是我到目前为止所拥有的:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<table id="table">
</table>
<script type="text/javascript">
//this code prints out the table.
let table = document.getElementById("table");
for (a = 0; a < 3; a++) {
let row = table.insertRow(a);
for (b = 0; b < 3; b++) {
row.insertCell(b);
table.rows[a].cells[b].innerHTML = a;
table.rows[a].cells[b].id = a + ":" + b;
}
}
var takenappt = ["0:1", "1:2"];
var repeat = takenappt.length;
//this code is supposed to go through my takenappt array and change the background color of certain table cells.
for (i = 0; i < repeat; i++) {
var appt = document.getElementById(takenappt[i]);
appt.style.backgroundColor = black;
}
</script>
</body>
</html>
我试图用 row:column 键存储每个表单元格,然后将某些键放入 takeappt 数组中,以便从数组中检索它们并使用它来更改该表单元格的颜色。任何帮助将不胜感激。
偶然的你
相关分类