您好,登錄后才能下訂單哦!
不話不多說(shuō)了,直接上代碼吧:
<div class="layui-btn-group demoTable" > <button class="layui-btn" id="hqsj" data-type="getCheckData">獲取選中行數(shù)據(jù)</button> <button class="layui-btn" data-type="getCheckLength">獲取選中數(shù)目</button> <button class="layui-btn" data-type="isAll">驗(yàn)證是否全選</button> <button class="layui-btn" οnclick="submitmychose()">提交選擇</button> </div> <table class="layui-table" lay-data="{width: 990, height:495, url:'<%=request.getContextPath()%>/admin/getSportcuDate', id:'idTest'}" lay-filter="demo"> <thead> <tr> <th lay-data="{type:'checkbox',width:80,fixed: 'left'}"></th> <th lay-data="{field:'sportId',width:100, sort: true, fixed: true}">ID</th> <th lay-data="{field:'sportName',width:290}">運(yùn)動(dòng)名</th> <th lay-data="{field:'sportTime',width:270, sort: true}">運(yùn)動(dòng)時(shí)長(zhǎng)</th> <th lay-data="{field:'sortId', width:225}">運(yùn)動(dòng)類型</th> </tr> </thead> </table> <script> var msg=""; var idlist=""; layui.use('table', function(){ var table = layui.table; //監(jiān)聽(tīng)表格復(fù)選框選擇 table.on('checkbox(demo)', function(obj){ }); var $ = layui.$, active = { getCheckData: function(){ //獲取選中數(shù)據(jù) msg=""; idlist=""; var checkStatus = table.checkStatus('idTest') ,data = checkStatus.data; for(var i=0; i<data.length;i++){ msg=msg+"周"+(i+1)+":"+data[i].sportName+" "; idlist =idlist+data[i].sportId+","; } } ,getCheckLength: function(){ //獲取選中數(shù)目 var checkStatus = table.checkStatus('idTest') ,data = checkStatus.data; layer.msg('選中了:'+ data.length + ' 個(gè)'); } ,isAll: function(){ //驗(yàn)證是否全選 var checkStatus = table.checkStatus('idTest'); layer.msg(checkStatus.isAll ? '全選': '未全選') } }; $('.demoTable .layui-btn').on('click', function(){ var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; }); }); function submitmychose(){ $('#hqsj').trigger("click"); } </script>
以上這篇Layui 帶多選框表格監(jiān)聽(tīng)事件以及按鈕自動(dòng)點(diǎn)擊寫法實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。