1.点击一行 选中
以下代码需要在表格渲染完成时加载。
1)当单击表格行时,把单选按钮设为选中状态
//当单击表格行时,把单选按钮设为选中状态 $(document).on("click", ".layui-table-body table.layui-table tbody tr", function() { var obj = event ? event.target : event.srcElement; var tag = obj.tagName; var checkbox = $(this).find("td div.laytable-cell-radio div.layui-form-radio I"); if (checkbox.length != 0) { if (tag == 'DIV') { checkbox.click(); } } }); $(document).on("click", "td div.laytable-cell-radio div.layui-form-radio", function(e) { e.stopPropagation(); });
2)当单击表格行时,把多选按钮设为选中状态
//当单击表格行时,把多选按钮设为选中状态 $(document).on("click", ".layui-table-body table.layui-table tbody tr", function() { var obj = event ? event.target : event.srcElement; var tag = obj.tagName; var checkbox = $(this).find("td div.laytable-cell-checkbox div.layui-form-checkbox I"); if (checkbox.length != 0) { if (tag == 'DIV') { checkbox.click(); } } }); $(document).on("click", "td div.laytable-cell-checkboxdiv.layui-form-checkbox", function(e) { e.stopPropagation(); });