[英]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.