The layui data table checkbox realizes the radio function

//Click to select (single selection) 
//
Click the row to check the checkbox event
    $(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 trs = tableDiv.find(".layui-unselect.layui-form-checkbox.layui-form-checked").parent().parent().parent();
           for(var i = 0;i<trs.length;i++){
              var ind = $(trs[i]).attr("data-index");
              if(ind!=index){
              var checkCell = tableDiv.find("tr[data-index=" + ind + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
                if (checkCell.length>0) {
                    checkCell.click();
                }
              }
           }
        //选中单击行
       var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
       if (checkCell.length > 0) {
            checkCell.click();
        }
        });
    $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
        e.stopPropagation();
    });
//Click to select (multiple selection) 
//
Click the row to check the checkbox event $(document) .on( "click", ".layui-table-body table.layui-table tbody tr", function() { var obj = event ? event.target : event.srcElement; var tag = obj.tagName; var index = $(this).attr('data-index'); var tableBox = $(this).parents(".layui-table-box"); // There is a fixed column 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"); if (checkCell.length > 0) { checkCell.click(); } }); $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function(e) { e.stopPropagation(); })

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325913414&siteId=291194637