廢話不多說(shuō)啦,直接貼上代碼吧!
<div class="layui-form-item layui-form-text"> <label class="layui-form-label"> <span class="x-red">*</span>權(quán)限表 </label> <div class="layui-input-block"> <table class="layui-table layui-input-block"> <tbody> <tr> <td> 客戶管理 <input class="checkbox_v1" type="checkbox" name="checkbox_v1" value="客戶管理" lay-filter="checkbox_v1"> </td> <td> <div class="layui-input-block"> <input name="checkbox1[]" type="checkbox" value="意向" class="checkbox1" lay-filter="checkbox1">意向 <input name="checkbox1[]" type="checkbox" value="會(huì)員" class="checkbox1" lay-filter="checkbox1">會(huì)員 </div> </td> </tr> <tr> <td> 施工管理 <input class="checkbox_v2" type="checkbox" name="checkbox_v2" value="施工管理" lay-filter="checkbox_v2"> </td> <td> <div class="layui-input-block"> <input type="checkbox" name="checkbox2[]" value="設(shè)計(jì)" class="checkbox2" lay-filter="checkbox2">設(shè)計(jì) <input type="checkbox" name="checkbox2[]" value="完工" class="checkbox2" lay-filter="checkbox2" >完工 <input type="checkbox" name="checkbox2[]" value="業(yè)主" class="checkbox2" lay-filter="checkbox2">業(yè)主 </div> </td> </tr> <tr> <td> 系統(tǒng)設(shè)置 <input class="checkbox_v3" type="checkbox" name="checkbox_v3" value="系統(tǒng)設(shè)置" lay-filter="checkbox_v3"> </td> <td> <div class="layui-input-block"> <input type="checkbox" name="checkbox3[]" value="個(gè)人資料" class="checkbox3" lay-filter="checkbox3" >個(gè)人 <input type="checkbox" name="checkbox3[]" value="BOSS" class="checkbox3" lay-filter="checkbox3" >BOSS </div> </td> </tr> </tbody> </table> </div> </div>
<script> layui.use([ 'layer', 'jquery', 'form'], function() { $ = layui.jquery; var form = layui.form ,layer = layui.layer; form.on('checkbox(checkbox_v1)', function(data){ var a = data.elem.checked; if(a == true){ $(".checkbox1").prop("checked", true); form.render('checkbox'); }else { $(".checkbox1").prop("checked", false); form.render('checkbox'); } }); form.on('checkbox(checkbox1)', function(data) { var b = data.elem.checked; if(b == true){ $(".checkbox_v1").prop("checked", true); form.render('checkbox'); }else { var item = $(".checkbox1"); var bool = false; for (var i = 0; i < item.length; i++) { if(item[i].checked == true){ bool = true; break; } } if(bool==false) { $(".checkbox_v1").prop("checked", false); form.render('checkbox'); } } }); form.on('checkbox(checkbox_v2)', function(data){ var a = data.elem.checked; if(a == true){ $(".checkbox2").prop("checked", true); form.render('checkbox'); }else { $(".checkbox2").prop("checked", false); form.render('checkbox'); } }); form.on('checkbox(checkbox2)', function(data) { var b = data.elem.checked; if(b == true){ $(".checkbox_v2").prop("checked", true); form.render('checkbox'); }else { var item = $(".checkbox2"); var bool = false; for (var i = 0; i < item.length; i++) { if(item[i].checked == true){ bool = true; break; } } if(bool==false) { $(".checkbox_v2").prop("checked", false); form.render('checkbox'); } } }); form.on('checkbox(checkbox_v3)', function(data){ var a = data.elem.checked; if(a == true){ $(".checkbox3").prop("checked", true); form.render('checkbox'); }else { $(".checkbox3").prop("checked", false); form.render('checkbox'); } }); form.on('checkbox(checkbox3)', function(data) { var b = data.elem.checked; if(b == true){ $(".checkbox_v3").prop("checked", true); form.render('checkbox'); }else { var item = $(".checkbox3"); var bool = false; for (var i = 0; i < item.length; i++) { if(item[i].checked == true){ bool = true; break; } } if(bool==false) { $(".checkbox_v3").prop("checked", false); form.render('checkbox'); } } }); </script>
以上這篇layui復(fù)選框的全選與取消實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com