<asp:RadioButtonList ID="rdbtn" runat="server" >
<asp:ListItem Value="firstitem">First</asp:ListItem>
<asp:ListItem Value="seconditem">Second</asp:ListItem>
</asp:RadioButtonList>
我需要根据某些条件设置要选择的First
列表项。还可以根据某些条件取消选择。
最佳答案
考虑将 RadioButtonList 包装在具有特定 id 或类的某个元素中,并使用它来搜索该元素或设置属性 ClientIdMode="Static"以避免 ASP.Net 更改 id。
如果您只想选择第一个,请找到第一个单选按钮并选择它。我不知道你说的情况是什么。
jQuery:
$(function() {
$("#rdbtn :radio:first").prop("checked", true);
});
选择特定值:
$(function() {
$("#rdbtn :radio[value='1']").prop("checked", true);
});
关于javascript - 如何使用jquery或javascript选择RadioButtonList中的列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32136923/