我在表格中放了一个复选框,当你点击它时,它会相应地改变背景颜色,就像这样...
任何帮助都将不胜感激,谢谢!
$("#table tr td :checkbox").bind("click change", function() {
$this = $(this); // cache the jquery object
if($this.is(':checked')) { $this.closest('tr').css('background-color', 'lightyellow'); }
else { $this.closest('tr').css('background-color', '#fff'); }
});
这个很好用,但是我想再进一步,无论你在表格行的哪里点击,它都会选中复选框并突出显示该行。
我尝试使用这段代码,但不幸的是它不起作用:
$("table tr").bind("click", function() {
$(this).parents("tr").find(":checkbox").attr('checked');
});
这里是HTML代码(为了提高可读性而删除了过多的内容...)
<td>Name</td>
<td>Description</td>
<td><input type="checkbox"></td>
任何帮助都将不胜感激,谢谢!