如果复选框为1,否为0,如何获取价值
这是我的代码:
$(document).ready(function(){
$('#table').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": false,
"responsive": true,
"autoWidth": false,
"pageLength": 10,
"ajax": {
"url": "../adapter/jobaccess/data.php",
type: "POST",
data: ({kd_entitas: kd_entitas,
usergroup: cmbUsergroup})
},
"columns": [
{ title: 'No.', name: 'No.', data: "urutan" },
{ title: 'Menu', data: "menudesc"},
{ title: 'Code', data: "menukey" },
{ title: 'Show', data: "alloshow1" },
{ title: 'Create', data: "allonew1" },
{ title: 'Edit', data: "alloedit1" },
{ title: 'Delete', data: "allodel1" },
{ title: 'Approve', data: "alloappr1" },
]
})
});
是否可以从我的jquery代码中获取价值? 谢谢
答案 0 :(得分:0)
我认为您正在寻找类似$(selector).prop('checked')
之类的东西,如果选中则返回true,如果未选中则返回false。您可以将click event绑定到该复选框。这是工作示例。
let count = 0;
$('#table').on('click', 'input[type="checkbox"]', function(){
count ++;
if($(this).prop('checked')){
console.log(1);
} else {
console.log(0);
}
console.log("Count: " + count);
});
.center {
text-align: center;
vertical-align: middle;
}
td, th {
padding: 5px;
}
tr {
height: 25px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table" style="empty-cells:hide;" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Field 1</th><th>Field 2</th><th>Field 3</th><th>Field 4</th>
</tr>
<tr>
<td class="center">
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
</tr>
<tr>
<td class="center">
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
</tr>
<tr>
<td class="center">
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
</tr>
<tr>
<td class="center">
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="checkbox">
</td>
</tr>
</table>