gpt4 book ai didi

javascript - 如何根据 td 为 tr 添加 css 属性

转载 作者:行者123 更新时间:2023-11-30 07:42:31 26 4
gpt4 key购买 nike

我想根据表中的 td 单元格值将类应用于 tr。

我的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
}

当我这样做时,每一行都有这个类悬停。但我希望只有当 td 值为 false 或 null 时才添加该类。

最佳答案

试试这个

$("table.k-focusable tbody tr td:contains('false')")

关于javascript - 如何根据 td 为 tr 添加 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13689133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com