【问题标题】: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);
                        }
                    });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-08-10
          • 1970-01-01
          • 2014-06-07
          • 1970-01-01
          • 2016-11-28
          • 2013-03-27
          • 1970-01-01
          • 2021-02-18
          相关资源
          最近更新 更多