【问题标题】:How to reset RadioButtonList on button click?如何在按钮单击时重置 RadioButtonList?
【发布时间】:2023-03-28 01:56:02
【问题描述】:

我有一个 RadioButtonList 有两个选项:完整和部分。默认选择是完整的。

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:ListItem Selected="True">Full </asp:ListItem>
    <asp:ListItem>Partial</asp:ListItem>
</asp:RadioButtonList>

我还有一个 jquery 函数,它可以在选择部分时隐藏某些元素,并在选择完整时重新出现。

$(document).ready(function () {
    $('#<%=RadioButtonList1.ClientID %>').change(function() {
        if($('#<%=RadioButtonList1.ClientID %> input:checked').val() == 'Partial') {
            $("#ddlLabel1").hide();
            $("#DropDownList1").hide();
        } else {
            $("#ddlLabel1").show();
            $("#DropDownList1").show();
        }
    });
});

当点击比较按钮时,这会导致隐藏的元素重新出现,但部分元素将保持选中状态。 This is a problem because these hidden elements should never be shown when partial is selected.

我的问题是:当单击比较按钮时,如何将单选按钮列表的值重置为完整?我知道有RadioButtonList1.ClearSelection(); 但我不想清除它,我想重置它。有什么建议吗?

【问题讨论】:

  • 查看SelectedIndex 属性。

标签: jquery asp.net radiobuttonlist


【解决方案1】:

您可以在比较按钮点击事件中添加以下代码

 RadioButtonList1.SelectedIndex = 0;
 RadioButtonList1.SelectedValue = "Full";

【讨论】:

  • 是的,在 Guy 的建议下才发现。我只需要第一行,顺便说一句。谢谢!
  • 一分钟之内,它让我! :P
猜你喜欢
  • 1970-01-01
  • 2013-07-05
  • 2022-01-01
  • 1970-01-01
  • 2013-09-25
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多