HTML
<table id="deviceTb" class="myDataTableStyle">
<thead>
<tr>
<th><input type="checkbox" name="cb-check-all"></th>
<th></th>
<th>设备</th>
<th>厂商</th>
<th>IP地址</th>
<th>更新时间</th>
<th>是否启用</th>
<th>操作</th>
</tr>
</thead>
<tr>
<td class="td-checkbox"><input type="checkbox"></td>
<td>111</th>
<td>111</td>
<td>111</td>
<td>111</td>
<td>111</td>
<td>111</td>
<td>111</td>
</tr>
</table>
js
var $table = $('#deviceTb');
$table.on("change",":checkbox",function() {
if ($(this).is("[name='cb-check-all']")) {
//全选
$(":checkbox",$table).prop("checked",$(this).prop("checked"));
}else{
//一般复选
var checkbox = $("tbody :checkbox",$table);
$(":checkbox[name='cb-check-all']",$table).prop('checked', checkbox.length == checkbox.filter(':checked').length);
}
}).on("click",".td-checkbox",function(event) {
//点击单元格即点击复选框
!$(event.target).is(":checkbox") && $(":checkbox",this).trigger("click");
});
//换页时清空全选状态
$(":checkbox[name='cb-check-all']").prop('checked', false);