Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取单元格中的所有复选框值_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript 如何获取单元格中的所有复选框值

Javascript 如何获取单元格中的所有复选框值,javascript,jquery,datatables,Javascript,Jquery,Datatables,我有jQuery数据表,其中有一些用于授予特权的复选框。 我需要将表值获取到数组中。请告诉我如何获取单元格内的复选框状态,而不仅仅是选中的状态。多谢各位 我的桌子 <table id="jqueryTable" name="tt" class="table table-striped table-bordered" cellspacing="0"> <thead> <tr> <th name="id"&g

我有jQuery数据表,其中有一些用于授予特权的复选框。 我需要将表值获取到数组中。请告诉我如何获取单元格内的复选框状态,而不仅仅是选中的状态。多谢各位

我的桌子

 <table id="jqueryTable" name="tt" class="table table-striped table-bordered" cellspacing="0">
    <thead>
        <tr>
            <th name="id">
                ID
            </th>
            <th name="name">
                PRIV_Name_Str
            </th>
            <th name="create">
                Create
            </th>
            <th>
                Edit
            </th>
            <th>
                View
            </th>
        </tr>
    </thead>
<table>

身份证件
私人姓名街
创造
编辑
看法
我的数据表查询

function LoadProduct(element) {
$.ajax({
    url: '/ADM_MAS_Privilege/GetFormData',
    data: { YourValue: $('#productCategory').val() },
    method: 'post',
    dataType: 'json',
    success: function (data) {
        var table =   $('#jqueryTable').dataTable({
            paging: true,
            sort: true,
            searching: true,
            scrollY: 200,
            data: data,
            bDestroy: true,

            "columnDefs":
            [{
                "targets": [2, 3, 4],
                "render": function (data, type, row, meta) {
                    console.log("XX " + meta.row + " " + meta.col);
                    return type === 'display' ?
                        '<input type="checkbox" id="p" class="chk" name="group' + meta.row + '" /> ' + data :
                        data;
            columns: [{ "data": "ID", "ID": "ID", "autoWidth": true },
            {
                "data": "PRIV_Name_Str", "PRIV_Name_Str": "PRIV_Name_Str", "autoWidth": true
            },
            {
                "data": "Create", "Create": "Create", "autoWidth": true
            },
            { "data": "Edit", "Edit": "Edit", "autoWidth": true },
            {
                "data": "View"                 

            }

            ]
        });
    }
});
函数加载产品(元素){
$.ajax({
url:“/ADM\u MAS\u Privilege/GetFormData”,
数据:{YourValue:$('#productCategory').val()},
方法:“post”,
数据类型:“json”,
成功:功能(数据){
变量表=$('#jqueryTable')。数据表({
是的,
排序:对,
搜索:是的,
卷轴:200,
数据:数据,
是的,
“columnDefs”:
[{
“目标”:[2,3,4],
“呈现”:函数(数据、类型、行、元){
console.log(“XX”+meta.row+“”+meta.col);
返回类型=='显示'?
''+数据:
数据;
列:[{“数据”:“ID”,“ID”:“ID”,“autoWidth”:true},
{
“数据”:“PRIV_Name_Str”,“PRIV_Name_Str”:“PRIV_Name_Str”,“autoWidth”:真
},
{
“数据”:“创建”、“创建”:“创建”、“自动宽度”:真
},
{“数据”:“编辑”,“编辑”:“编辑”,“自动宽度”:true},
{
“数据”:“视图”
}
]
});
}
});
})

我的jQuery函数用于读取数据表

$('#upload').click(function () {
var table = document.getElementById("jqueryTable");
var tableArr = [];
for (var i = 1; i < table.rows.length; i++) {
    tableArr.push({

        ID: table.rows[i].cells[0].innerHTML,
        PRIV_Name_Str: table.rows[i].cells[1].innerHTML,

        Create: table.rows[i].cells[2].innerHTML,
        Edit: table.rows[i].cells[3].innerHTML,

        View: table.rows[i].cells[4].innerHTML

    });
}
$('#上传')。单击(函数(){
var table=document.getElementById(“jqueryTable”);
var tableArr=[];
对于(变量i=1;i
}))


我尝试了table.rows[I].cells[2].innerHTML.getElementById(“p”)。检查为偶数,但不起作用。

因为您使用的是jQuery:

document.getElementById("jqueryTable").each(function (index, element) {
  tableArr.push({
    ID: element.cells[0].innerHTML,
    PRIV_Name_Str: element.cells[1].innerHTML,

    Create: element.cells[2].innerHTML,
    Edit: element.cells[3].innerHTML,

    View: element.cells[4].innerHTML
  })
})

可以在每个单元格中找到元素和选中的属性:

for (var i = 1; i < table.rows.length; i++) {
    var cells = table.rows[i].cells;
    tableArr.push({
        ID: cells[0].innerHTML,
        PRIV_Name_Str: cells[1].innerHTML,
        Create: cells[2].querySelectorAll('input')[0].checked,
        Edit: cells[3].querySelectorAll('input')[0].checked,
        View: cells[4].querySelectorAll('input')[0].checked 
    });
}
for(变量i=1;i
document.queryselectoral('table input[type=“checkbox”]”)。forEach(cb=>console.log(cb.checked));
谢谢,但它返回了“”这只是复选框定义。还有其他方法吗?我想你可以从那里获得其他属性,比如elem.length或elem.data(“某些数据属性”)