layui获取表格中的checkbox,并取消选中。
根据同一行中其他列数据的变化动态取消checkbox选中
//index 为当前行行号
$('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', false);
//一定要重新渲染,不然不生效
form.render('checkbox');
例子:
<script>
var form = layui.form, table = layui.table;
table.render({
elem: '#tableData'
, data: items
, skin: { size: 'sm' }
, cellMinWidth: 90 //定义所有列的最小宽度
, maxPer: 0.45
, cols: [[
{field: 'checkbox', type:'checkbox', fixed: 'left'}
, { field: 'stockCount', title: '取消提货数', templet: '<div><input type="number" class="layui-input stockCount" min="0" max="{{d.stockCount}}" data-index="{{d.LAY_TABLE_INDEX}}" value=""/></div>'}
]]
, page: false
, limit: 1000
, done: function (res) {
//自定义处理
}
});
//监听stockCount的变化
//根据stockCount列是否变化来动态的取消checkBox选中
$(document).on('blur','.stockCount',function(obj){
let index = parseInt($(this).attr('data-index'));
let value = $(this).val();
console.log("value = ======"+value)
table.cache.tableData[index].count = value;
//取消变化列中checkBox选中值
$('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', false);
form.render('checkbox');
})
</script>