jQuery radio的取值与赋值_ide

HTML

<div class="weui-cell">
<div class="weui-cell__hd"><label class="weui-label">性别</label></div>
<div class="weui-cell__bd">
<input class="weui-radio" name="sex" type="radio" value="1" style="width: 18px;height: 18px;vertical-align: text-bottom;margin-bottom: 2px;">男
<input class="weui-radio" name="sex" type="radio" value="2" style="width: 18px;height: 18px;vertical-align: text-bottom;margin-bottom: 2px;margin-left: 12px">女
<!--<input type="radio" class="radio-la" name="n" id="check-1" hidden="">
<input type="radio" class="radio-la" name="n" id="check-2" hidden="">-->
</div>
</div>

取值:

let identity = $('input:radio[name=identity]:checked').val();
let sex = $('input:radio[name=sex]:checked').val();

回显:


let identity = obj.identity;
let sex = obj.sex;
$(":radio[name='identity'][value='" + identity + "']").prop("checked", "checked");
$(":radio[name='sex'][value='" + sex + "']").prop("checked", "checked");