Javascript 复选框单击jquery datatables不工作的事件

Javascript 复选框单击jquery datatables不工作的事件,javascript,jquery,Javascript,Jquery,我在网格中使用了jQuery数据表。 有两个网格,每个网格中都有一个复选框。我需要在选中/取消选中复选框时生成一个事件 我试过这个,但不起作用。请让我知道我做错了什么 $(document).ready(function () { $('.cBSAGrid tr td').click(function (event) { alert('0'); }); }); 及 我的数据表jquery $.

我在网格中使用了jQuery数据表。 有两个网格,每个网格中都有一个复选框。我需要在选中/取消选中复选框时生成一个事件

我试过这个,但不起作用。请让我知道我做错了什么

  $(document).ready(function () {
            $('.cBSAGrid tr td').click(function (event) {
                alert('0'); 
            });
        });

我的数据表jquery

$.ajax({
                type: "POST",
                url: "/BSA/BSAExceptionGrid",
                data: '{ policynumber: "' + txtpolicy.val() + '",clientname:"' + clientname.val() + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    div.css("display", "none"); 

                    $('#BSAGrid').DataTable({
                        paging: false,
                        searching: false,
                        destroy: true,
                        "bInfo" : false,
                        data: response,
                        columns: [
                            { "data": "Logged_ID" },
                            { "data": "Logged_ID" }, 
                            { "data": "CustomerName" },
                            { "data": "ClientType" }                           

                        ], 
                        aoColumnDefs: [
                        {
                            aTargets: [0],    // Column number which needs to be modified
                            mRender: function (o, v) {   // o, v contains the object and value for the column
                                return '<input type="checkbox" id="chkBSA" name="chkBSA" />';
                            }
                            //,sClass: 'tableCell'       // Optional - class to be applied to this table cell
                        }
                        ,
                         {
                             aTargets: [1],
                             visible: false
                         }
                        ],
                        select: {
                            style: 'os',
                            selector: 'td:first-child'
                        },
                        order: [[1, 'asc']]

                    });

                },
                failure: function (response) {
                    alert(response);
                },
                error: function (response) {
                    alert(response.responseText);
                }
            }); 
$.ajax({
类型:“POST”,
url:“/BSA/BSA ExceptionGrid”,
数据:“{policynumber:”+txtpolicy.val()+”,clientname:“+clientname.val()+”}”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(响应){
div.css(“显示”、“无”);
$('#BSAGrid')。数据表({
分页:false,
搜索:假,
摧毁:没错,
“bInfo”:假,
数据:答复,
栏目:[
{“data”:“Logged_ID”},
{“data”:“Logged_ID”},
{“数据”:“客户名称”},
{“数据”:“ClientType”}
], 
aoColumnDefs:[
{
a目标:[0],//需要修改的列号
mRender:function(o,v){//o,v包含列的对象和值
返回“”;
}
//,sClass:'tableCell'//可选-要应用于此表单元格的类
}
,
{
数据目标:[1],
可见:假
}
],
选择:{
风格:“os”,
选择器:“td:第一个孩子”
},
订单:[[1,‘asc']]
});
},
故障:功能(响应){
警报(响应);
},
错误:函数(响应){
警报(response.responseText);
}
}); 
HTML


记录的\u ID
客户名称
客户端类型
试试下面的代码:

$(document).ready(function(){
$(document).on("change", "#chkBSA", function() {
alert('click')
});
});

您可以在同一列中包含onChange事件侦听器,并将其添加到您的列return text onChange=“gridCheckboxChange(this);”

如果您使用的是bootstrap 4自定义复选框,则将类添加到复选框中

.className {left: 0;z-index: 1;width: 1.25rem;height: 1.25rem;}

像这样做
$(文档)。在(“click”,“.CHECKBOXCLASS”,function(){
谢谢。这很有效。但奇怪的是,我把它放在表类,即cBSAGrid上,但它只对复选框单击有效,而不对行单击有效,或者这是正常行为吗?使用click事件更改只对复选框有效。
$(文档)。在(“click”,“#BSAGrid tr”,函数(){alert('click');});
$(document).ready(function(){
$(document).on("change", "#chkBSA", function() {
alert('click')
});
});
.className {left: 0;z-index: 1;width: 1.25rem;height: 1.25rem;}