layui 데이터베이스 에서 체크 상자 의 값 을 가 져 오고 기본 선택 방법

다음 과 같다.

<!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 는 데이터베이스 에서 체크 상자 의 값 을 가 져 오고 기본 선택 방법 은 작은 편집 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.참고 하 시기 바 랍 니 다.여러분 들 이 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기