当需要选中或取消选中该行中的复选框时,需要更改整行的样式。基于复选框更改样式w/jQuery
function myFunc() {
if ($(".chkbx:checked").length) {
$(this).parent().parent().css("background-color","red");
} else {
$(this).parent().parent().css("background-color","green");
}
}
myFunc();
$(".chkbx").change(myFunc);
<table>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
</table>
我觉得我失去了一些东西......
没有什么不对,但通常您会在使用jQuery框架时看到以$为起点的jQuery对象开始的变量。 '$ color'使得它看起来好像该变量正在尊重jQuery,在我看来,'color'将是一个更好的选择,因为它只是一个字符串。 – Justin808