我正在使用jquery和c#动态地将radiobuttonlist listitem设置为selected。我想创建一个重置类型按钮,将radiobuttonlist所选项目重置回列表中的第一项。
jQuery / jsTree函数当前正在重置文本框和隐藏字段:
$('#ContentPlaceHolder1_hfNodeID').val('');
$('.txtPage').val('');
$('.rblContentTypesGetAll').val();
$('.contentPageForm').show(),
.rblContentTypesGetAll
是我要重置的radiobuttonlist(或选择最顶级的listitem)。
表单的HTML:
<asp:Panel ID="PagesForm" CssClass="contentPageForm" runat="server">
<asp:HiddenField ID="hfNodeID" runat="server" Value="" />
<table>
<tr>
<td>Page</td>
<td><asp:TextBox ID="txtPage" CssClass="txtPage" runat="server" /><span class="validate">*</span><br />
<asp:RequiredFieldValidator ID="rfvPage" runat="server" CssClass="validate" ControlToValidate="txtPage" Display="Dynamic" ErrorMessage="Page Name Required" ValidationGroup="page" /></td>
</tr>
<tr>
<td>Content Type</td>
<td>
<asp:RadioButtonList id="rblContentTypesGetAll" CssClass="rblContentTypesGetAll" OnLoad="rblContentTypesGetAll_Load" runat="server" >
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td> <asp:Button ID="Submit" runat="server" OnClick="PageSubmit_Click" Text="Save" ValidationGroup="page" />
<asp:Button ID="Cancel" runat="server" OnClick="Cancel_Click" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
答案 0 :(得分:2)
$('#rblContentTypesGetAll_0').attr('checked', 'checked');
修改强>
Bry4n说以下为他效劳:
$("#ContentPlaceHolder1_rblContentTypesGetAll_0").attr("checked", "checked");
答案 1 :(得分:0)
您是否错过了val
的参数?
$('.rblContentTypesGetAll').val('');