gpt4 book ai didi

javascript - 使用 Javascript 进行 ASP.NET 复选框列表验证

转载 作者:行者123 更新时间:2023-11-28 02:05:57 26 4
gpt4 key购买 nike

我有一个 asp.net 复选框列表,如下所示:

<asp:CheckBoxList ID="cblCurrency" runat="server">
<asp:ListItem Text="ALL" Value="0"></asp:ListItem>
<asp:ListItem Text="A" Value="1"></asp:ListItem>
<asp:ListItem Text="B" Value="2"></asp:ListItem>
<asp:ListItem Text="C" Value="3"></asp:ListItem>
<asp:ListItem Text="D" Value="4"></asp:ListItem>
</asp:CheckBoxList>

要求是,如果选择“ALL”,则应从所有其他复选框中删除选中的属性,如果选择任何其他复选框,则应删除“ALL”的选中属性。我想使用 javascript 来实现这一点,但最好是使用 jQuery。如果您知道该怎么做,请回复。如有帮助,我们将不胜感激。

最佳答案

这是我的解决方案:

$("#<%=cblCurrency.ClientID%> input").click(function () {
if ($('<%= "#" + cblCurrency.ClientID + "_0" %>').is(":checked")) {
$("#<%=cblCurrency.ClientID%> input:checkbox").not(this).prop("checked", false);
}
});

基本上,我们利用由 ASP.NET 生成并在最后的 ID 属性中使用的复选框索引。就像这个:cblCurrency_1 表示索引 1 处的复选框。

关于javascript - 使用 Javascript 进行 ASP.NET 复选框列表验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17757507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com