首页 > 解决方案 > 在数据表jQuery中更改复选框状态为true的类按钮

问题描述

我使用数据表,但我遇到了问题。

在表中我有自定义复选框,我需要检查框的状态,为此我使用这个函数:

 var table = $('#table').dataTable();
    var rowcollection = table.$(".subUsed:checked", { "page": "all" });

    rowcollection.each(function (index, elem) {
        var checkboxValue = $(elem).val();
        if (checkboxValue === true) {
            table.find(".addSubItem").removeClass('hide')
        } else {
            table.find(".addSubItem").addClass("hide")
        }
    });

它是检查,在checkboxValue我得到一个结果,我想检查值是否为,然后在具有类.addSubItem的按钮中删除类隐藏。

但在某些情况下,它不会被删除。

标签: jquerydatatable

解决方案


提供了新代码,也许会对某人有所帮助:

$(document).ready(function () {
    var table = $('#table').DataTable();
    table.rows().every(function () {
        if (this.nodes().to$().find(".input:checked").val()) {
            this.nodes().to$().find(".buttonClass").removeClass('hide')
        } 
    })
});

推荐阅读