<div class="layui-form-item"> <label class="layui-form-label">操作系统</label> <div lay-filter="os" id="search_checkbox" class="layui-input-block"> <input type="checkbox" value="windows" title="windows"> <input type="checkbox" value="centos" title="centos"> </div> </div> var arr_box = []; $('#search_checkbox input[type=checkbox]:checked').each(function() { arr_box.push($(this).val()); }); //取的是value值 //layui checkbox 赋值 str数组 name ID名称 //数组可用 var s=1,2 var arr=s.split(","); //获取layui 多选内容 layui checkbox 需要包裹一层id common.getCheckbox=function (idname) { var arr_box = []; $('#'+idname+' input[type=checkbox]:checked').each(function() { arr_box.push($(this).val()); }); return arr_box.join(","); } //layui checkbox 赋值 str数组 name ID名称 //数组可用 var s=1,2 var arr=s.split(","); common.setCheckbox=function(str,name){ //先要重置属性 //var unitTypeCheckbox = $("input[name='"+name+"']"); var unitTypeCheckbox =$('#'+name+' input[type=checkbox]') for (var i = 0; i < unitTypeCheckbox.length; i++) { unitTypeCheckbox[i].checked = false; } //把相同的属性设置为true for (var j = 0; j < str.length; j++) { for (var i = 0; i < unitTypeCheckbox.length; i++) { if (unitTypeCheckbox[i].value == str[j]) { //unitTypeCheckbox[i].value = unitType[j]; unitTypeCheckbox[i].checked = true; } } } } //获取状态 $(".对象").prop("checked"); 返回布尔值 $('#checkbox-id').is(':checked') //多选变单选 form.on('checkbox(card)', function(data){ $("#card [type='checkbox']").each(function(){ this.checked=false; }); $(this).prop('checked',true); //多个多选变单选 需要加重新渲染 form.render('checkbox'); }); //多选变单选2 form.on('checkbox(card)', function(data){ $('input[name="card"]').prop("checked",false); $(this).prop('checked',true); form.render('checkbox'); });
关注"都市百货" 了解南陵
微信咨询wanglf2r(不拉群 发广告者勿加)
热门评论