简体   繁体   English

如何使用jquery或javascript在RadioButtonList中选择列表项?

[英]How to select the listitem in RadioButtonList using jquery or javascript?

<asp:RadioButtonList ID="rdbtn" runat="server" >
                                <asp:ListItem Value="firstitem">First</asp:ListItem>
                                <asp:ListItem Value="seconditem">Second</asp:ListItem>
                            </asp:RadioButtonList>

I need to set the First listitem to be selected based on some condition. 我需要根据某些条件设置要选择的First Also to deselect based on some condition. 还要根据某些条件取消选择。

Consider wrapping the RadioButtonList in some element with specific id or class and using that to search the element or setting the property ClientIdMode="Static" to avoid ASP.Net from changing the id. 考虑将RadioButtonList包装在具有特定ID或类的某些元素中,并使用该元素搜索元素或设置属性ClientIdMode =“ Static”以避免ASP.Net更改ID。

If all you want is the first to be selected then, find the first radiobutton and select it. 如果您要选择的是第一个,则找到第一个单选按钮并选择它。 I don't know what is your condition that you are speaking of. 我不知道你在说什么。

jQuery: jQuery的:

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

Select with specific value: 选择特定值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM