我正在使用 jquery 数据表来列出我的内容,其中有复选框选择和选定的内容发布数据,但在提交的表单中仅发送当前页面数据。
我的数据表代码是:
$('#select').dataTable( {
"order": [[ 2, "desc" ]],
"lengthMenu": [[50, -1], [50, "All"]],
"columnDefs": [
{ orderable: false, targets: [0, 1, 3, 5] },
{ "width": "20px", "targets": [0, 1] },
{ "width": "80px", "targets": [5] }
],
});
当我点击提交时,它只会提交当前页面值的复选框数组。
我已经引用了这个链接Pagination with selected check boxes. Checkboxes will only work on current pagination page. jQuery datatables但是那里提供的带有链接和链接的解决方案不起作用。
最佳答案
您可以使用以下代码获取所有选中的复选框值,这可能对您有所帮助
var myArray = [];
var id = "";
var oTable = $("#example").dataTable();
$(".class1:checked", oTable.fnGetNodes()).each(function() {
if (id != "") {
id = id + "," + $(this).val();
} else {
id = $(this).val();
}
});
关于javascript - 复选框仅适用于 jQuery 数据表中的当前分页页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30723911/