Javascript:更改表格单元格的 bgColor

pti*_*obj 1 javascript

我想更改表格中一个特定单元格的颜色:为什么以下操作不起作用?

document.getElementById('myTable').rows[i].cells[j].bgColor="#mybgColor";
Run Code Online (Sandbox Code Playgroud)

其中ij肯定是在行和单元格范围内的一些整数。我不需要任何花哨的 JQuery 左右,只需要这个简单的命令。

gil*_*ly3 5

CSS 样式将覆盖bgColor已弃用的属性。使用.style.backgroundColor代替.bgColor

document.getElementById('myTable').rows[i].cells[j].style.backgroundColor = "#003366";
Run Code Online (Sandbox Code Playgroud)