【发布时间】:2017-06-22 08:36:41
【问题描述】:
我的 HTML 代码:
<table class="tableclass">
<th>id</th><th>Name</th><th>Value</th>
<tr>
<td>001</td>
<td>Name 001</td>
<td>This is some value for Key 001</td>
</tr>
<tr>
<td>002</td>
<td>Name 002</td>
<td>This is some value for Key 002</td>
</tr>
<tr>
<td>003</td>
<td>Name 003</td>
<td>This is some value for Key 003</td>
</tr>
<tr>
<td>004</td>
<td>Name 004</td>
<td>This is some value for Key 004</td>
</tr>
</table>
我可以使用 CSS 显示替代颜色:
tr:nth-child(even) {
background-color: #CCD1D1;
}
和我的 jQuery 突出显示点击的表格行:
$(".tableclass tr").click(function(){
$(this).addClass("rowHighlight");
});
班级.rowHighlight{background-color:#AEB6BF;}
使用此代码,我无法更改具有 css 背景的奇数行的背景颜色。我也希望能够更改该行的背景。
我该怎么做?
谢谢。
【问题讨论】:
-
将背景颜色添加到 td 而不是 tr 所以,.rowHighlight td {background-color:#AEB6BF;}
-
谢谢大家 .. 成功了!!!!
-
更新了边框问题,您可以根据需要进行调整
-
tr.rowHighlight{}好一点