2012-09-18 53 views
7

我想在用户在TextBox中输入文本后清除Radiobutton列表选择。我尝试了下面的代码,但它似乎并没有工作,并没有显示任何错误。请让我知道是否有任何建议。使用jquery清除单选按钮列表选择

function ClearRadioButtonList() { 
    var checkboxlistid9 = "#<%= rblLst.ClientID %>"; 
    $('.checkboxlistid9').attr('checked',false);  
} 

<telerik:RadMaskedTextBox ID="txtCode" runat="server" Mask="###-##-####" SelectionOnFocus="CaretToBeginning"> 
    <ClientEvents OnBlur="ClearRadioButtonList" /> 
</telerik:RadMaskedTextBox> 

<asp:RadioButtonList ID="rblLst" runat="server" RepeatDirection="Horizontal"> 
    <asp:ListItem Value="1">Unknown</asp:ListItem> 
    <asp:ListItem Value="2">Not Applicable</asp:ListItem> 
</asp:RadioButtonList> 

回答

11

相反的:

$('.checkboxlistid9').attr('checked',false); 

尝试:

$('.checkboxlistid9').removeAttr('checked'); 

此外,我认为你的jQuery选择是错误的

$('.checkboxlistid9') 

我没有看到一个类checkboxlistid9上你的asp:RadioButtonList

更改查询选择到:

$("table[id$=rblLst] input:radio:checked").removeAttr("checked"); 

或者

$("table[id$=rblLst] input:radio").each(function (i, x){ 
    if($(x).is(":checked")){ 
     $(x).removeAttr("checked"); 
    } 
}); 
+0

谢谢。现在正在工作。我将代码更改为$(“table [id $ = rblLst] input:radio:checked”)。removeAttr(“checked”); – nav100

0
$('.checkboxlistid9').removeAttr('checked'); 
1

您应该使用prop()。此外,each()迭代:

$('.checkboxlistid9').each(function (index, elem){ 
    $(elem).prop('checked',false); 
}) 
2

单选按钮将是代表RadioButtonList元素的后代,你可以用#<%= rblLst.ClientID %> input[type=radio]选择它们,并使用.prop()删除选中的物业。

function ClearRadioButtonList() { 
    $("#<%= rblLst.ClientID %> input[type=radio]").prop('checked',false);  
}