MVC代码:
<div class="form-group">
<label for="Gender" class="col-sm-2 control-label">性别</label>
<div class="col-md-8">
<label class="checkbox-inline">
@Html.RadioButton("Gender", 1, new { @id = "radio1", @name = "Gender" })男
</label>
<label class="checkbox-inline">
@Html.RadioButton("Gender", 0, new { @id = "radio0", @name = "Gender" })女
</label>
</div>
</div>
html代码:
<div class="form-group">
<label for="Gender" class="col-sm-2 control-label">性别</label>
<div class="col-md-8">
<label class="checkbox-inline">
<input id="radio1" name="Gender" type="radio" value="1" />男
</label>
<label class="checkbox-inline">
<input id="radio0" name="Gender" type="radio" value="0" />女
</label>
</div>
</div>
jQuery 获取:
1.var Gender =$(‘input[name="Gender"]:checked‘).val();
2.var Gender =$(‘input:radio:checked‘).val();
3.var Gender =$(‘input[@name="Gender "][checked]‘);
遍历获取
$(‘input[name="Gender "]‘).each(function(){
alert(this.value);
});
如果要取具体某个radio的值,比如第二个radio的值,这样写
$(‘input[name="Gender"]:eq(1)‘).val()
赋值:
if (result.Gender == "1")
$("input[name=‘Gender‘][value=1]").attr("checked", true);
else
$("input[name=‘Gender‘][value=0]").attr("checked", true);
2016 系统设计第一期 (档案一)jQuery radio 取值赋值
原文:http://www.cnblogs.com/foreverfendou/p/5149611.html