【发布时间】:2012-11-09 10:47:43
【问题描述】:
我有两个复选框列表,我想获取其中选中元素的计数。以下是我的代码:
<div id="divAreaListingByLocation">
<asp:CheckBoxList ID="chklstArea" CssClass="chkarea" RepeatColumns="6" RepeatDirection="Vertical"
runat="server" OnSelectedIndexChanged="chklstArea_SelectedIndexChanged" AutoPostBack="true">
</asp:CheckBoxList>
</div>
<asp:Repeater ID="repRooms" runat="server" OnItemDataBound="repRooms_ItemDataBound">
<ItemTemplate>
<div style="height: 100%; float: none;">
<asp:Panel ID="pnlRoomheader" runat="server" Style="width: 98%; background-color: #86ADD6;
color: #4A4A4A; height: 20px; margin-top: 10px; text-align: left; padding: 5px;
font-size: 15px; font-weight: bold;">
<asp:Label ID="lblAreaName" runat="server"></asp:Label>
<asp:Label ID="lblAreaId" Style="display: none;" runat="server"></asp:Label>
</asp:Panel>
<div id="divRoomListingByLocation" style="padding-bottom: 10px; padding-top: 10px;">
<asp:CheckBoxList ID="chkRoomList" CssClass="chkRooms" RepeatColumns="6" RepeatDirection="Vertical"
runat="server">
</asp:CheckBoxList>
<asp:Label ID="lblRoomMessage" Text="This Area does not have any room." ForeColor="Red"
runat="server"></asp:Label>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
我想要做的是:如果用户没有选中这两个复选框中的任何一个,那么它会提示一个警报,说在单击一个按钮时从两个列表中选中一个复选框。
我已经尝试过使用类,但该类被附加到复选框列表的 html 中的表格渲染中。
【问题讨论】:
-
你有没有尝试过?
-
请发布您尝试过的内容。类似的问题已经被问过:stackoverflow.com/questions/872296/….
-
@FelixKling 你提到的问题与我在那个问题中的问题不同,他问的是如何计算一个页面的所有复选框的数量..以及我的复选框列表中的问题..
-
@Visions:嗯,当然你必须调整选择器......如果这是你的问题(不清楚,因为你没有发布你尝试过的内容),我建议你看看在文档中:api.jquery.com/category/selectors。查看生成的 HTML,而不是 asp 代码也可能会有所帮助。
标签: javascript jquery asp.net checkbox