我想將類應用於tr,具體取決於表中的td單元值。如何添加一個tr的css屬性取決於td
我的HTML
<table class="k-focusable">
<tr>
<th>Name</th>
<th>Favorite color</th>
<th> status</th>
</tr>
<td>James</td>
<td>red</td>
<td>false</td>
</tr>
<tr>
<td>John</td>
<td>blue</td>
<td>true</td>
</tr>
</table>
var cellIndexMapping = { 2: true };
$("table.k-focusable tbody tr").each(function (rowIndex) {
$(this).find("td").each(function (cellIndex) {
if (x[cellIndex]) {
var c = $(this).text();
if (($.trim(c) == "false") || ($.trim(c) == "null")) {
$("table.k-focusable tbody tr").find("td").addClass("hover");
}
}
});
});
.hover
{
font-weight:bold
}
當我這樣做
,每一行是有這個類hover.But我想,類如果TD值爲false或null時只添加。
謝謝,但我想添加該類到tr。 – Findings
@Findings/..檢查編輯後 –