Bootstrap

jquery获取以及判断单选框、开关选中值

 HTML代码块

<input type="radio" name="sex" value="0" title="男">
<input type="radio" name="sex" value="1" title="女" checked>

 

 jquery代码块

var val = $('input[name="sex"]:checked').val();//单选框选中值

//查找name为sex且value值为0的元素,并设置它的状态为选中。
let num = '0'
$("input[name=sex][value=" + num + "]").prop("checked", true);

//通过判断开关,如果选中则为1,否则为0
$("input[name=xxx]").prop("checked") ? "1" : "0";
;