选择复选框时,jQuery更改表行的背景颜色

Par*_*van 4 jquery jquery-ui jquery-plugins

我在表中有5列.第1列有一个名为name ="strurl1"的复选框,name ="strurl2",name ="strurl3"等.如果选中,表行背景颜色将从#f1f1f1更改为#e5e5e5.

我试过但代码不能正常工作.

主要的CSS是

.overviewtable tbody tr td {
    line-height:normal;
    border-top:1px solid #FFF;
    border-bottom:1px solid #c4c4c4;
    height:35px;
    padding-top:10px;
    padding-bottom:5px;
    background-color:#f1f1f1;
}

.overviewtable tbody tr td.col1 {
    width:316px;
    padding-left:15px;
    border-left:4px solid #FFF;
    font-size:12px;
    color:#999999;
}
Run Code Online (Sandbox Code Playgroud)

表列名为col1,col2,col3,col4和col5.

有帮助吗?提前致谢.

rkw*_*rkw 7

你想要突出显示行吗?使用.closest()方法获取row元素,然后添加一个突出显示类:http://jsfiddle.net/etVc8/3/

$(function() {
    $('td:first-child input').change(function() {
        $(this).closest('tr').toggleClass("highlight", this.checked);
    });
});
Run Code Online (Sandbox Code Playgroud)

  • 如果我在表的<th>中有一个复选框,检查/取消选中所有复选框怎么办? (2认同)