[英]checkbox click event with jquery datatables not working
我已经将 jQuery Datatables https://datatables.net/用于我的网格。 有两个网格,每个网格中都有一个复选框。 当复选框被选中/取消选中时,我需要生成一个事件。
我试过这个,但它不起作用。 请让我知道我在这里做错了什么.......
$(document).ready(function () {
$('.cBSAGrid tr td').click(function (event) {
alert('0');
});
});
和
$(document).ready(function () {
$('#BSAGrid tr').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);
}
});
HTML
<div id="BSAGridContainer" style="display:none;">
<table id="BSAGrid" class="cBSAGrid table table-responsive">
<thead>
<tr>
<th></th>
<th >Logged_ID</th>
<th>Client Name</th>
<th>Client Type</th>
</tr>
</thead>
</table>
</div>
试试下面的代码:
$(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;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.