Use:
$('input[id*=rblGender][type=radio][value="M"]')prop('checked', true);
or
$('#<%=rblGender.ClientID %>').find("input[value='M']").attr("checked", "checked");
Вопрос
I need to set the default text of radiobutton as Male in the function fnclear()
<asp:RadioButtonList ID="rblGender" runat="server" RepeatDirection="horizontal">
<asp:ListItem Selected="True" Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
</asp:RadioButtonList>
<script type="text/javascript">
function fnClear() {
$('#<%= txtName.ClientID %>').val('');
$('#<%= rblGender.ClientID %>').val('M');
}
</script>
Решение
Use:
$('input[id*=rblGender][type=radio][value="M"]')prop('checked', true);
or
$('#<%=rblGender.ClientID %>').find("input[value='M']").attr("checked", "checked");
Другие советы
You can try this code to set default check value 'Male'
$('#<%=rblGender.ClientID %> [type=radio][value=M]').prop('checked', true);
Set radio button by text
$("input:radio").each(function () {
var idVal = $(this).attr("id");
if ($("label[for='" + idVal + "']").text() == "Male") {
$(this).prop("checked", true);
}
});