- 找到tableTree.js中的复选选中相关代码
//注册点击事件。 checkBox点击事件 tableBody.on("click",'td.layui-table-col-special',function (e) { _layui.stope(e) var div = $(this).children('div.layui-unselect'); div.hasClass('layui-tableEdit-checked') ? div.removeClass('layui-tableEdit-checked') : div.addClass('layui-tableEdit-checked'); });
_layui.stop 是阻止冒泡事件,导致复选框无法监听的原因
-
实现子节点关联勾选取消(直接在源码上修改的,应该也可以通过方法事件,请自行尝试)
//注册点击事件。 checkBox点击事件 tableBody.on("click",'td.layui-table-col-special',function (e) { debugger _layui.stope(e) var div = $(this).children('div.layui-unselect'); div.hasClass('layui-tableEdit-checked') ? div.removeClass('layui-tableEdit-checked') : div.addClass('layui-tableEdit-checked'); // 子节点数据处理,勾选或者取消勾选子节点 var tr = this.parentElement; var currentLvl = tr.getAttribute("data-lvl"); var flag = true; var next = tr.nextSibling; while(flag){ var nextLvl = next.getAttribute("data-lvl"); if(!nextLvl || currentLvl == nextLvl){ flag = false; }else{ if(div.hasClass('layui-tableEdit-checked')){ $(next.firstChild).children('div.layui-unselect').addClass('layui-tableEdit-checked'); }else{ $(next.firstChild).children('div.layui-unselect').removeClass('layui-tableEdit-checked'); } } next = next.nextSibling; } });
layui treeTable 复选框监听无效 实现子节点关联勾选
最新推荐文章于 2024-03-23 06:17:57 发布