复选框回显

tech2022-12-12  116

js

var navigations= $("#navigations").val().split(",");//后台获取val的值 for(var i = 0; i < navigations.length ;i++){ $("input[name='navigation'][value='"+navigations[i]+"']").attr("checked",true); }

html

<div class="form-group"> <div id="company2"> <label class="col-sm-3 control-label">导航栏权限:</label> <div id="Navigation" class="col-sm-8" class="layui-input-block"> <input type="checkbox" name="navigation" value="1" title="监测预警" lay-skin="primary" >监测预警 <input type="checkbox" name="navigation" value="2" title="监管执法" lay-skin="primary" >监管执法 <input type="checkbox" name="navigation" value="3" title="决策支持" lay-skin="primary" >决策支持 <input type="checkbox" name="navigation" value="4" title="应急指挥" lay-skin="primary" >应急指挥 <input type="checkbox" name="navigation" value="5" title="协同办公" lay-skin="primary" >协同办公 <input type="checkbox" name="navigation" value="6" title="领导驾驶舱" lay-skin="primary" >领导驾驶舱 </div> </div> </div>

获取val 

function update() { var arr_box = [];//获取值 $('input[type=checkbox]:checked').each(function() { arr_box.push($(this).val()); }); var navigations = arr_box.join(","); $('#menuIds').val(menuIds); var role = $('#signupForm').serialize()+"&navigations="+navigations// 你的formid;; $.ajax({ cache : true, type : "POST", url : "/sys/role/update", data : role, // 你的formid async : false, error : function(request) { alert("Connection error"); }, success : function(r) { if (r.code == 0) { parent.layer.msg(r.msg); parent.reLoad(); var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引 parent.layer.close(index); } else { parent.layer.msg(r.msg); } } }); }

 

最新回复(0)