我用以下代码在javascript中创建了一个表:
var table = document.createElement('table')
table.style.verticalAlign = "top";
table.align = 'center';
table.createCaption().innerHTML ='Employee List'
table.caption.backgroundColor ="grey"
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
cell1.id = 'employee_off'
var cell2 = row.insertCell(1);
cell2.id = 'employee_on'
document.body.appendChild(table)
employee_listManager();
问题是,即使字幕背景为灰色,当我加载页面时,背景还是白色...
我正在互联网上搜索如何更改他的颜色,但标题却什么也没发现。
我应该仅为字幕创建跨度还是td?
谢谢
最佳答案
使用syle
属性使用CSS样式,类似这样。
table.caption.style.backgroundColor ="grey";
//--------------^
代替
table.caption.backgroundColor ="grey";
DEMO