<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <link type="text/css" href="" media="all"> <link type="text/css" href="" media="all"> <link href="https://at.alicdn.com/t/font_563459_gq4dpdw2k61xajor.css" /> <style> #node input[type=checkbox] { display: inline; } </style> </head> <body> <div> <form> <input type="hidden" value="#(role.roleid ??)"> <div> <label>角色名称</label> <div> <input value="#(role.name)" type="text" autocomplete="off" placeholder="请输入角色名称"> </div> </div> <div> <label>角色描述</label> <div> <textarea value="#(role.description)" cols="30" rows="10" placeholder="请输入角色描述"></textarea> </div> </div> <div> <label>菜单权限</label> <div> <input type="checkbox" lay-skin="primary" value="接待人员管理" title="接待人员管理"> <input type="checkbox" lay-skin="primary" value="接待车辆管理" title="接待车辆管理"> <input type="checkbox" lay-skin="primary" value="来访信息录入" title="来访信息录入"> <input type="checkbox" lay-skin="primary" value="我的待办" title="我的待办"> <input type="checkbox" lay-skin="primary" value="人员接待统计" title="人员接待统计"> <input type="checkbox" lay-skin="primary" value="园区接待统计" title="园区接待统计"> <input type="checkbox" lay-skin="primary" value="角色管理" title="角色管理"> <input type="checkbox" lay-skin="primary" value="用户管理" title="用户管理"> <input type="checkbox" lay-skin="primary" value="接待礼遇管理" title="接待礼遇管理"> <input type="checkbox" lay-skin="primary" value="操作日志" title="操作日志"> <input type="checkbox" lay-skin="primary" value="登录日志" title="登录日志"> </div> </div> <div> <div> <button lay-submit lay-filter="form">提交</button> <button type="reset">取消</button> </div> </div> </form> </div> </body> <script type="text/javascript" src="" charset="utf-8"></script> <script type="text/javascript" src="" charset="utf-8"></script> <script type="text/javascript"> /** * 将从数据库中获取到的菜单权限以,分隔开,并默认选中 */ layui.use('form', function() { var form = layui.form; var functional='#(role.functional)'; var groupCheckbox = $("input[name='functional']"); for (i = 0; i < groupCheckbox.length; i++) { var val =groupCheckbox[i].value; if(functional.split(',').indexOf(val)!=-1){ groupCheckbox[i].checked=true; } } form.render(); }); </script> </html>
layui.use('form', function(){ var form = layui.form; //监听提交 layui.code form.on('submit(form)', function(data){ //获取复选框选中的值 var groupCheckbox=$("input[name='functional']"); var functional=""; for(i=0;i<groupCheckbox.length;i++){ if(groupCheckbox[i].checked){ var val =groupCheckbox[i].value; if(functional.length>0){ functional+=","+val; }else{ functional+=val; } } } data.field.functional=functional; $.post("/role/editOk",data.field,function(res){ if(res.code=="0"){ layer.msg(res.data); }else{ layer.msg(res.data); } }) return false; }); }); </script>
以上这篇layui从数据库中获取复选框的值并默认选中方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章: