【发布时间】:2011-09-26 05:21:51
【问题描述】:
我有一张“漂亮”类的桌子。
每一行旁边都有一个复选框,用于使用表单选择数据。
我希望能够单击单元格并勾选/取消勾选复选框。
我有这个工作使用
$(document).ready(function () {
$('.pretty tr').toggle(function() {
$(this).find(':checkbox').attr('checked', true);
}, function() {
$(this).find(':checkbox').attr('checked', false);
});
});
除此之外,我希望在选中复选框时更改单元格背景颜色,如果取消选中则不更改。
我没有任何运气这样做,有什么想法吗?
我已经尝试添加
$(this).addClass('cssclassname');
上面没有运气:(
仅编辑一个更新,“漂亮”类已经具有以下 css,这使得表格中的数据每行的颜色不同。
似乎当我尝试 jquery toggleClass 函数时,它并没有将它应用到已经存在的 CSS 上?
table.pretty {
background: whitesmoke;
border-collapse: collapse;
}
table.pretty th, table.pretty td {
border: 1px silver solid;
padding: 0.2em;
}
table.pretty th {
background: gainsboro;
text-align: left;
}
table.pretty caption {
margin-left: inherit;
margin-right: inherit;
}
table.pretty tr:nth-child(odd) { background-color:#eee; }
table.pretty tr:nth-child(even) { background-color:#fff; }
【问题讨论】:
标签: jquery