【问题标题】:Set default value in radio button [closed]在单选按钮中设置默认值[关闭]
【发布时间】:2014-02-25 04:21:57
【问题描述】:
我需要在函数fnclear()中将radiobutton的默认文本设置为Male
<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>
【问题讨论】:
标签:
javascript
jquery
asp.net
radiobuttonlist
【解决方案1】:
用途:
$('input[id*=rblGender][type=radio][value="M"]')prop('checked', true);
或
$('#<%=rblGender.ClientID %>').find("input[value='M']").attr("checked", "checked");
【解决方案2】:
您可以尝试使用此代码设置默认检查值“男性”
$('#<%=rblGender.ClientID %> [type=radio][value=M]').prop('checked', true);
【解决方案3】:
通过文本设置单选按钮
$("input:radio").each(function () {
var idVal = $(this).attr("id");
if ($("label[for='" + idVal + "']").text() == "Male") {
$(this).prop("checked", true);
}
});