方法一:如何根據(jù)條件判斷是否默認(rèn)選中table表格前面的復(fù)選框

創(chuàng)新互聯(lián)公司一直秉承“誠信做人,踏實做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個客戶多一個朋友!為您提供網(wǎng)站設(shè)計、成都網(wǎng)站制作、成都網(wǎng)頁設(shè)計、微信平臺小程序開發(fā)、成都網(wǎng)站開發(fā)、成都網(wǎng)站制作、成都軟件開發(fā)、app軟件開發(fā)公司是成都本地專業(yè)的網(wǎng)站建設(shè)和網(wǎng)站設(shè)計公司,等你一起來見證!
table.render({
elem: '#userTable'
, url: '../sysRole/getUserList'
, title: '用戶列表'
, page: true //開啟分頁
, cols: [[
{type:'checkbox'}
, {field: 'userName',sort: true, title: '用戶名稱'}
, {field: 'account',sort: true, title: '登錄賬戶'}
, {field: 'deleteFlg',sort: true, title: '是否啟用'}
]]
,done: function(res, page, count){
//可以自行添加判斷的條件是否選中
//這句才是真正選中,通過設(shè)置關(guān)鍵字LAY_CHECKED為true選中,這里只對第一行選中
res.data[0]["LAY_CHECKED"]='true';
//下面三句是通過更改css來實現(xiàn)選中的效果
var index= res.data[0]['LAY_TABLE_INDEX'];
$('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
$('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
}
});方法二:checkFuntion()當(dāng)翻頁或加載時判斷是否選中復(fù)選框,input第一行禁用,第二行選中,第三行未選中
<script>
//存儲選中的設(shè)備Id
var checkId=[];
</script>
<table class="layui-hide" id="deviceList" lay-filter="deviceFilter"></table>
//模板頁定義復(fù)選框,可以直接寫js控制是否選中
<script type="text/html" id="checkboxTpl">
{{#
function checkFuntion(arry){
var isTrue=false;
for(var index in arry){
if(arry[index]==d.id){
isTrue=true;
break;
}
}
return isTrue;
};
if(d.deviceAreaId!=null){ }}
<input type="checkbox" lay-skin="primary" value="{{d.id}}" lay-filter="deviceIdFilter" disabled>
{{# } else {
if(checkFuntion(checkId)){ }}
<input type="checkbox" lay-skin="primary" id="{{d.id}}" isCheck="true" value="{{d.id}}" lay-filter="deviceIdFilter" checked>
{{# } else { }}
<input type="checkbox" lay-skin="primary" id="{{d.id}}" isCheck="false" value="{{d.id}}" lay-filter="deviceIdFilter">
{{# } }}
{{# } }}
</script>
table.render({
elem: '#deviceList'
, url: '../devices/findALL' //數(shù)據(jù)接口
, title: '儀表表'
,height:'480px'
,where:{"gatewaySN":selectPid,"channel":searchId}
, page: true //開啟分頁
, cols: [[ //表頭
{field:'id',width: '5%',templet: '#checkboxTpl',title: '<div id="checkAll" οnclick="selectAll()" all="false" class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div></div>'}
// ,{field: 'id', title: 'ID', width: '5%', sort: true, title: 'ID'}
, {field: 'deviceName', width: '25%', sort: true, title: '儀表名稱'}
, {field: 'type', width: '15%', sort: true, title: '儀表類型'}
, {field: 'entryName', width: '15%', sort: true, title: '能耗分項'}
, {field: 'deviceDesc', width: '40%', sort: true, title: '儀表描述'}
]]
,done: function(res, page, count){
//每次翻頁或者重載時判斷是否全選
if ( $('input[isCheck="false"]').length==0){
$("#checkAll").attr('all','true');
$("#checkAll").addClass('layui-form-checked');
}else {
$("#checkAll").attr('all','false');
$("#checkAll").removeClass('layui-form-checked');
}
}
});
//全選按鈕事件
function selectAll() {
var checkAll = $("#checkAll");
if (checkAll.attr('all') == "false") {
console.log($('input[isCheck="false"]'));
$('input[isCheck="false"]').each(function () {
$(this).next().click();
});
checkAll.attr('all', 'true');
checkAll.addClass('layui-form-checked');
} else if (checkAll.attr('all') == "true") {
$('input[isCheck="true"]').each(function () {
$(this).next().click();
});
checkAll.attr('all', 'false');
checkAll.removeClass('layui-form-checked');
}
}
以上這篇layui默認(rèn)選中table的CheckBox復(fù)選框方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。
本文題目:layui默認(rèn)選中table的CheckBox復(fù)選框方法
URL分享:http://chinadenli.net/article10/gsjedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、定制網(wǎng)站、網(wǎng)頁設(shè)計公司、微信公眾號、網(wǎng)站設(shè)計公司、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)