layui中radio的动态加载(进入修改页面时,设置radio)
前端代码:
<div class="layui-form-item"> <label class="layui-form-label">状态</label> <div class="layui-input-block"> <input type="radio" name="status" value="0" title="正常"> <input type="radio" name="status" value="1" title="短封"> <input type="radio" name="status" value="2" title="永封"> </div> </div>
js 设置代码:
// 设置数据 if (data != null) { layui.form.val('datafile', { "qq" : data.qq, "qq_pass" : data.qq_pass, "bind_phone" : data.bind_phone, "user_id" : data.staff_id, "deblock_time" : data.deblock_time, "status" : $("input[name=status][value=0]").attr("checked", data.status == 0 ? true : false), "status" : $("input[name=status][value=1]").attr("checked", data.status == 1 ? true : false), "status" : $("input[name=status][value=2]").attr("checked", data.status == 2 ? true : false), }); }
<div class="layui-form-item"> <label class="layui-form-label">状态</label> <div class="layui-input-block"> <input type="radio" name="status" value="0" title="正常"> <input type="radio" name="status" value="1" title="短封"> <input type="radio" name="status" value="2" title="永封"> </div> </div>