我有3个单选按钮,这些按钮在mvc3视图中呈现。我正在使用视图模型,以下是呈现radioButtonFor的View.aspx页面:
<%= Html.RadioButtonFor(model => model.Input.YesNoMaybe, item.Value, new { id = String.Format("Input_YesNoMaybe_{0}", item.Value) })%>
有人可以帮我解决如何使用jQuery简单地访问并选择3个单选按钮的第二 选中吗?
到目前为止,我尝试了以下多种变体:
$("input[name='Input.YesNoMaybe_1']").attr('checked', 'checked');
这是呈现的HTML:
<div id="divEscrowFeeSplit">
<input type="radio" value="1" name="Input.YesNoMaybe" id="Input_YesNoMaybe_1" data-val-required="required." data-val-range-min="1" data-val-range-max="2147483647" data-val-range="select a valid option" data-val-number="Must be a number." data-val="true">
<label for="Input_YesNoMaybe_1">Yes</label>
<input type="radio" value="2" name="Input.YesNoMaybe" id="Input_YesNoMaybe_2">
<label for="Input_YesNoMaybe_2">No</label>
<input type="radio" value="3" name="Input.YesNoMaybe" id="Input_YesNoMaybe_3" checked="checked">
<label for="Input_YesNoMaybe_3">Maybe</label>
答案 0 :(得分:1)
试试这个:
$("#Input_YesNoMaybe_1").attr('checked', 'checked');