我正在通过 DOM 元素和 innerHTML 向表中添加行。它有效,唯一的问题是cell3。背景颜色不会显示。我相信这是因为 cell3 有一个附加元素。帮助?
var table = document.getElementById("vessel_tab");
var rowCount = table.rows.length;
var row = table.insertRow();
//row.style.backgroundColor="#7F9EBE"; doesn't work as bg for entire row
var cell1 = row.insertCell(0);
cell1.style.backgroundColor="#7F9EBE"; working
cell1.innerHTML = "<font color='#000'><strong>EMS 345</strong></font>";
cell1.colSpan = 2;
var cell3 = row.insertCell(1);
cell3.style.backgroundColor="#7F9EBE"; !NOT WORKING
var element1 = document.createElement("input");
element1.type = "checkbox";
cell3.innerHTML = "<img title='remove' src='images/delete-row-icon1.png' class='sub_icon remove'/> ";
cell3.appendChild(element1);