<form id="editForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" style="margin-top: 5px;">单选一</label>
<div class="col-sm-1" style="width:15px;margin-top: 12px;">
<input type="radio" name="percentType" value="single">
</div>
<label class="col-sm-2 control-label" style="margin-top: 5px;">单选二</label>
<div class="col-sm-1" style="width:15px;margin-top: 12px;">
<input type="radio" name="percentType" value="policies">
</div>
</div>
</form>
1.第一种使用attr方法设置属性值
在jquery1.6前版本使用正常,在jquery1.6后版本存在问题,按钮只有第一次设置选中状态正常,之后再设置选中状态不生效。
<script type="text/javascript">
$("#editForm input:radio[value='policies']").attr('checked',true);
</script>
2.第二种使用prop方法设置属性值
在jquery1.6之后版本,对于checked,selected等进行状态改变时推荐使用prop方法设置属性值
<script type="text/javascript">
$("#editForm input:radio[value='policies']").prop('checked',true);
</script>