【问题标题】:How to select the listitem in RadioButtonList using jquery or javascript?如何使用 jquery 或 javascript 在 RadioButtonList 中选择列表项?
【发布时间】:2015-08-21 18:16:46
【问题描述】:
<asp:RadioButtonList ID="rdbtn" runat="server" >
                                <asp:ListItem Value="firstitem">First</asp:ListItem>
                                <asp:ListItem Value="seconditem">Second</asp:ListItem>
                            </asp:RadioButtonList>

我需要根据某些条件设置要选择的First listitem。也可以根据某些条件取消选择。

【问题讨论】:

标签: javascript c# jquery asp.net radiobuttonlist


【解决方案1】:

考虑将 RadioButtonList 包装在具有特定 id 或类的元素中,并使用它来搜索元素或设置属性 ClientIdMode="Static" 以避免 ASP.Net 更改 id。

如果你想要的只是第一个被选中,那么找到第一个单选按钮并选择它。我不知道你说的是什么情况。

jQuery:

$(function() {
   $("#rdbtn :radio:first").prop("checked", true);
});

选择特定值:

   $(function() {
       $("#rdbtn :radio[value='1']").prop("checked", true);
    });

【讨论】:

  • 对于第二个单选按钮,我使用了radio:second,但它在我的应用程序中引发了错误。
  • 没有:second-selector,你搜索单选按钮的条件是什么?有价值吗?有文字吗?
  • 带值..例如,如果值为“第一个”,则选择第一个单选按钮,不应选择第二个单选按钮..对于另一个条件,反之亦然..即选择了第二个单选按钮如果值为“秒”..谢谢..
  • 我的第二个示例正是这样做的,找到具有特定值的单选按钮并选择它。您应该可以使用该方法。
  • 非常感谢。第二个例子很好。按预期工作。
猜你喜欢
  • 1970-01-01
  • 2022-11-23
  • 1970-01-01
  • 2015-02-08
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 2019-02-06
相关资源
最近更新 更多