layui从数据库中获取复选框的值并默认选中,详细代码:layui从数据库中获取复选框的值并默认选中,详细代码: !doctype htmlhtml lang="en"headmeta charset="UTF-8"title/titlelink rel="stylesheet" type="text/css"href="../../../static/js/css/layui.css" rel="external nofollow" media="all"link rel="stylesheet" type="text/css"href="../../../
<!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从数据库中获取复选框的值并默认选中方法,希望能给大家一个参考。
沃梦达教程
本文标题为:layui从数据库中获取复选框的值并默认选中方法
基础教程推荐
猜你喜欢
- CSS list-style-type属性使用方法 2023-12-21
- vue-router中的hash和history两种模式的区别 2024-03-21
- jQuery实现每隔一段时间自动更换样式的方法分析 2024-04-08
- CSS元素居中布局的简单方法 2024-04-26
- 详解CSS不定宽溢出文本适配滚动 2022-11-13
- jQuery实现带动画效果的二级下拉导航方法 2024-03-12
- Layui treetable 复选框联动解决方案 2024-03-20
- ajax从JSP传递对象数组到后台的方法 2023-02-15
- 关于 sencha touch:ExtJS、SenchaTouch – FormPanel 无 2022-09-15
- input file样式修改以及图片预览删除功能详细概括(推荐) 2024-02-09