页面代码:
<div class="radio1">
<label for="and"><input type="radio" id="and" name="relation" value="并且" title="并且">并且</label>
<label for="or"><input type="radio" id="or" name="relation" value="或者" title="或者">或者</label>
<label for="user-define"><input type="radio" id="user-define" name="relation" value="自定义" title="自定义">自定义</label>
</div>
页面显示:
代码:
//获得选中的radio的值
var relationVal = $('input[name="relation"]:checked').val();
//设置不选中任何一个radio
$("input:radio[name='relation']").attr("checked",false);
//设置满足某个条件后设置选中某个radio
if(...){
$("#and").prop("checked",true);
$("#or").prop("checked",false); //可省略
$("#user-define").prop("checked",false); //可省略
}
//也可以
$("input:radio[value='并且']").prop("checked",true);