在checkbox datatables中获取值的方法如下:
<table id="myTable">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="checkbox" value="1"></td>
<td>John Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td><input type="checkbox" class="checkbox" value="2"></td>
<td>Jane Smith</td>
<td>jane@example.com</td>
</tr>
<!-- 添加更多行 -->
</tbody>
</table>
$(document).ready(function() {
var table = $('#myTable').DataTable();
$('#myTable').on('change', '.checkbox', function() {
var selectedValues = [];
$('.checkbox:checked').each(function() {
selectedValues.push($(this).val());
});
console.log(selectedValues);
});
});
在上面的代码中,我们使用on()
方法来监听表格中checkbox的变化事件。当checkbox的状态发生变化时,我们遍历所有选中的checkbox,并将其值添加到selectedValues
数组中。最后,我们将selectedValues
数组打印到控制台。
这样,你就可以在checkbox datatables中获取选中的值了。
注意:以上代码仅为示例,实际应用中可能需要根据具体情况进行调整。
腾讯技术开放日
腾讯云GAME-TECH沙龙
腾讯云GAME-TECH沙龙
DBTalk技术分享会
GAME-TECH
发现教育+科技新范式
DBTalk
云+社区技术沙龙[第5期]
云+社区技术沙龙[第9期]
云+社区技术沙龙[第6期]
领取专属 10元无门槛券
手把手带您无忧上云