我想遍历表中的行并只执行更改背景颜色如果column2
单元格不包含值或空单元格。这是我现在所拥有的,但所有的行都是有颜色的,我只需要在column2
中的单元格为空时应用的逻辑。条件逻辑,如果列单元格为空
JS:
// loops through rows
for (var i = 0; rows; rows = tbody.rows[i]; i++) {
//loops through cells
for (var j = 1; col; col = rows.cells[j]; j++) {
//gets cells of current row
cells = rows[i].getElementsByTagName('td');
//gets cells of col 1
ocells = rows.cells[j].getElementByTagName('td');
while (rows.cells[j] === null) {
//condition here>>
}
}
}
HTML:
<div id="table">
<table name="tbody" id="tbody1">
<tr>
<td>col1 Val1</td>
<td>col2 Val2</td>
</tr>
<tr>
<td>col1 Val3</td>
<td>col2 Val4</td>
</tr>
</table>
</div>
任何帮助,将不胜感激!
安置自己的HTML代码...上面 – ATOzTOA
HTML是寻找一个JavaScript的解决方案。 – charlie