繁体   English   中英

使用jQuery对表中的每一行进行着色

[英]Colorize every row in a table with jQuery

我已经尝试了几种方法,但从来没有完全达到我的目标。 如果我使用select-All-button,我基本上想要改变每一行的背景颜色:

<th class="w70 c" id="project_table_header_checkbox">
    <input type="checkbox" name="all" value="1" onclick="$('#project-table input[type=checkbox]').not('[disabled]').prop('checked', $(this).prop('checked') ); colorizeRows();">
</th>

我也有一种改变一行颜色的工作方式:

$(":checkbox").change(function() {
    $(this).parents('tr').find('td').toggleClass("bgcolor_grey", this.checked)
})

我认为在我的复选框上只有一个监听器会很有用,只要状态发生变化就会改变行颜色。

我该怎么做呢?


编辑:

 <div class="fullwidth c" id="project-table">
        <div class="box">
            <table>

            <tr>
                <th class="w70 c" id="project_table_header_checkbox">

选中/取消选中后,使用selectAll触发其他复选框上的change

$('#selectAllId').change(){
    $(":checkbox").not(this).prop('checked', this.checked).change()
});

现在,将触发切换行类的当前更改事件处理程序代码

保持你的更改功能为一个复选框,并添加这样的东西到你的全选复选框(我建议你使用ids来形成和选择所有复选框)

$('#select_all').change(function() {
    var checkboxes = $('#your_form').find(':checkbox');
    if($(this).is(':checked')) {
        checkboxes.prop('checked', true);
    } else {
        checkboxes.prop('checked', false);
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM