<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取radio的值</title>
<script type="text/javascript">
function test(){
var radios = document.getElementsByName("loan");
var value = 0;
for(var i=0;i<radios.length;i++){
if(radios[i].checked == true){
value = radios[i].value;
}
}
alert(value);
}
</script>
</head>
<body>
<input type="radio" name="loan" value="1" checked="checked" onclick="test()">男
<input type="radio" name="loan" value="2" onclick="test()">女
<input type="radio" name="loan" value="3" onclick="test()">保密
<input type="button" name="get" value="获取" >
</body>
</html>
设置:
$("#id").prop("checked",true);