Display selected items of a checkboxlist
2012-01-18 15:42
344 查看
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=CheckBoxList1.ClientID %>').click(function () {
var str = "";
$('#message').text(str);
$('#<%=CheckBoxList1.ClientID %> input[type=checkbox]:checked').each(function () {//Apply a jQuery selector to retrieve the checked boxes and apply the each function to each element returned
str = str + " " + $(this).next().text();
// Retrieve the text of the selected CheckBox and append to the local string
// Each of the checkbox elements is rendered as a <input
// type="checkbox"> and <label> pair. The label holds the text of the
// element. Hence, when retrieving the description of the element, we have
// used $(this).next().text(), where $(this) refers to the current
// checkbox element and next() refers to the consecutive <label> element.
$('#message').text(str); //After the execution of the each() function, display the local string in the div area 'message'
})
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Value="1" Text="Standard"></asp:ListItem>
<asp:ListItem Value="2" Text="Silver"></asp:ListItem>
<asp:ListItem Value="3" Text="Gold"></asp:ListItem>
<asp:ListItem Value="4" Text="Premier"></asp:ListItem>
</asp:CheckBoxList>
</div>
<br />
<div id="message"></div>
</form>
</body>
</html>
<head runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=CheckBoxList1.ClientID %>').click(function () {
var str = "";
$('#message').text(str);
$('#<%=CheckBoxList1.ClientID %> input[type=checkbox]:checked').each(function () {//Apply a jQuery selector to retrieve the checked boxes and apply the each function to each element returned
str = str + " " + $(this).next().text();
// Retrieve the text of the selected CheckBox and append to the local string
// Each of the checkbox elements is rendered as a <input
// type="checkbox"> and <label> pair. The label holds the text of the
// element. Hence, when retrieving the description of the element, we have
// used $(this).next().text(), where $(this) refers to the current
// checkbox element and next() refers to the consecutive <label> element.
$('#message').text(str); //After the execution of the each() function, display the local string in the div area 'message'
})
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Value="1" Text="Standard"></asp:ListItem>
<asp:ListItem Value="2" Text="Silver"></asp:ListItem>
<asp:ListItem Value="3" Text="Gold"></asp:ListItem>
<asp:ListItem Value="4" Text="Premier"></asp:ListItem>
</asp:CheckBoxList>
</div>
<br />
<div id="message"></div>
</form>
</body>
</html>
相关文章推荐
- 'ddlXXX' has a SelectedIndex which is invalid because it does not exist in the list of items
- 'ddlCities' has a SelectedValue which is invalid because it does not exist in the list of items
- Speed up the display of Delphi list components
- 【iLifer: beta版】Full list of work items
- #707 – 从WPF程序中拖拽一个List列表的数据到Excel(Dragging a List of Items from a WPF Application into Excel)
- Check/Uncheck all Items in an ASP.NET CheckBox List using jQuery
- Using jQuery and SPServices to Display List Items
- CheckBoxList1的Items宽度控制
- ASP.NET - Code Samples - Disable CheckboxList Items
- P23 (**) Extract a given number of randomly selected elements from a list.
- 3.4 Templates -- Displaying A List of Items(展示一个集合)
- P23 (**) Extract a given number of randomly selected elements from a list.
- Separate list items by their class or kind_of in ruby
- 复制单链表成为新的链表,然后return the number of items in the new list
- Is it possible to use a checkbox in a split button list instead of the gear icon?
- drpDep.SelectedValue = "123" 的效率低于 drpDep.SelectedIndex = drpDep.Items.IndexOf(drpDep.Items.FindByValue(“123”));
- Checkbox Text List :: Extension of Iconified Text tutorial
- Retrieving the list of items in a directory all at once
- sharepoint2010:The number of items in this list exceeds the list view threshold, which is 20000 items.
- 黑马程序员 ASP.NET中 CheckboxList.Items.Count=0的解决办法