Layui中使⽤table组件时让某些⾏的checkbox或者radio⾃动选
Layui Table点击⾏时选中单选框
//注:test是table原始容器的属性 lay-filter="对应的值"
('row(tableId)', function (obj) {
//选中⾏样式
//选中radio样式
});
Layui Table点击⾏时选中复选框
$(document).on("click", ".layui-table-body table.layui-table tbody tr", function () {
var index = $(this).attr('data-index');
var tableBox = $(this).parents('.layui-table-box');
//存在固定列
if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length > 0) {
tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
} else {
tableDiv = tableBox.find(".layui-table-body.layui-table-main");
}
var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
var classStr=$(checkCell).parent().attr("class");
htmlradio添加切换事件
if(classStr.indexOf("layui-form-checked")>=0){
$(checkCell).parent().removeClass("layui-form-checked");
}else{
$(checkCell).parent().addClass("layui-form-checked");
}
//            if (checkCell.length > 0) {
//                checkCell.click();
//            }
});
//对td的单击事件进⾏拦截停⽌,防⽌事件冒泡再次触发上述的单击事件(Table的单击⾏事件不会拦截,依然有效)
$(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
e.stopPropagation();
});

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。