作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 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/
我是一名优秀的程序员,十分优秀!