取得 单选的值
<form class="layui-form" action=""> <div class="layui-form-item"> <label class="layui-form-label">审核</label> <div class="layui-input-block"> <input type="radio" name="state" value="1" title="通过" checked=""> <input type="radio" name="state" value="2" title="驳回"> </div> </div> var state = $('input[name="state"]:checked').val(); //获取单选的值。 1或者2
layui.use('form', function () { var $ = layui.jquery, form = layui.form; $.ajax({ type: "post", url: "/Shared/GetPiDate", data: {}, async: true, dataType: "json", success: function (data) { $("input[name=sex][value=1]").attr("checked", data.UserSex == 1 ? true : false); $("input[name=sex][value=2]").attr("checked", data.UserSex == 2 ? true : false); form.render(); //更新全部 } } }); 下面要加个引号不加引号会报错。因为添加的时候,没有值。 $(function(){ if("[[${teach?.sex}]]"!=""){ $("input[name=sex][value=1]").attr("checked", '[[${teach?.sex}]]' == 1 ? true : false); $("input[name=sex][value=2]").attr("checked", '[[${teach?.sex}]]' == 2 ? true : false); } }); if("[[${standardSample?.state}]]"!=""){ $("input[name=state][value='块状']").attr("checked", '[[${standardSample?.state}]]' == '块状' ? true : false); $("input[name=state][value='粉末']").attr("checked", '[[${standardSample?.state}]]' == '粉末' ? true : false); $("input[name=state][value='液体']").attr("checked", '[[${standardSample?.state}]]' == '液体' ? true : false); } form.render(); //更新全部
站长微信:xiaomao0055
站长QQ:14496453