jQuery radio的取值与赋值

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");

猜你喜欢

转载自www.cnblogs.com/zxyun/p/9330533.html