您好,登錄后才能下訂單哦!
如下:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="../../../static/js/css/layui.css" rel="external nofollow" media="all"> <link rel="stylesheet" type="text/css" href="../../../static/css/index-gb.css" rel="external nofollow" media="all"> <link rel="stylesheet" href="http://at.alicdn.com/t/font_563459_gq4dpdw2k61xajor.css" rel="external nofollow" /> <style> #node input[type=checkbox] { display: inline; } </style> </head> <body> <div class="div-con"> <form class="layui-form layui-form1"> <input type="hidden" name="roleid" id="id" value="#(role.roleid ??)"> <div class="layui-form-item form-item1"> <label class="layui-form-label form-label1">角色名稱</label> <div class="layui-input-block input-block1"> <input value="#(role.name)" type="text" name="name" autocomplete="off" placeholder="請輸入角色名稱" class="layui-input layui-input1"> </div> </div> <div class="layui-form-item form-item1"> <label class="layui-form-label form-label1">角色描述</label> <div class="layui-input-block input-block1"> <textarea value="#(role.description)" name="description" id="" cols="30" rows="10" class="layui-textarea textarea-me" placeholder="請輸入角色描述"></textarea> </div> </div> <div class="layui-form-item form-item1"> <label class="layui-form-label form-label1">菜單權限</label> <div class="layui-input-block input-block4"> <input type="checkbox" name="functional" lay-skin="primary" value="接待人員管理" title="接待人員管理"> <input type="checkbox" name="functional" lay-skin="primary" value="接待車輛管理" title="接待車輛管理"> <input type="checkbox" name="functional" lay-skin="primary" value="來訪信息錄入" title="來訪信息錄入"> <input type="checkbox" name="functional" lay-skin="primary" value="我的待辦" title="我的待辦"> <input type="checkbox" name="functional" lay-skin="primary" value="人員接待統計" title="人員接待統計"> <input type="checkbox" name="functional" lay-skin="primary" value="園區接待統計" title="園區接待統計"> <input type="checkbox" name="functional" lay-skin="primary" value="角色管理" title="角色管理"> <input type="checkbox" name="functional" lay-skin="primary" value="用戶管理" title="用戶管理"> <input type="checkbox" name="functional" lay-skin="primary" value="接待禮遇管理" title="接待禮遇管理"> <input type="checkbox" name="functional" lay-skin="primary" value="操作日志" title="操作日志"> <input type="checkbox" name="functional" lay-skin="primary" value="登錄日志" title="登錄日志"> </div> </div> <div class="layui-form-item form-item-btn"> <div class="layui-input-block layui-input-block5"> <button class="layui-btn" lay-submit lay-filter="form">提交</button> <button type="reset" class="layui-btn layui-btn-primary" id="reset">取消</button> </div> </div> </form> </div> </body> <script type="text/javascript" src="../../../static/js/layui.all.js" charset="utf-8"></script> <script type="text/javascript" src="../../../static/js/jquery-3.2.0.js" 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從數據庫中獲取復選框的值并默認選中方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。