datatables实现批量操作
话不多说,直接上代码
<table id="datalist" class="table table-border table-bordered table-hover table-bg table-sort text-c " > <thead> <tr class="text-c"> <th width="25"><input type="checkbox" name="checkSth" id="checkAll" value=""></th> <th width="25">序号</th> <th >学校编号</th> <th >班级编号</th> <th >班主任</th> <th >手机</th> <th >联系电话</th> </tr> </thead> </table> 数据添充: function bindData() { oTable = $("#datalist").dataTable({ "sAjaxSource": "${ctx}/community/list?ptype=Ab03", "columns": [ {"data":null,"sClass": "text-c", "sWidth": "50","mRender":function (data,type,full) { return "<input type=checkBox name='checkSth' value="+data.CKE035+">"; }}, { "data": null, "sClass": "text-c", "sWidth": "50", "mRender": function (data, type, full, cr) { return cr.settings._iDisplayStart + cr.row + 1; } }, { "data": "CAB001"}, //学校编号 { "data": "CKE035"}, //班级编号 { "data": "CKE036"}, //班主任 { "data": "CKE034"}, //手机 { "data": "AAE005"}, //联系电话 ] }); }
获取选择内容
var obj = document.getElementsByName("checkSth");
var checkVal= [];
for(k in obj){
if(obj[k].checked)
checkVal.push(obj[k].value);
}
$('#checkCKE035').val(checkVal);
}
checkCKE035是表单的一个元素,提交后可以在后台获取,从而实现在批量处理