1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3 <title></title>
4
5 <script language="javascript" src="js/jquery-1.5.js"></script>
6
7 <script language="javascript">//each遍历
8 $(function() {
9 $("input[name=names]").click(function() {
10 var arr = new Array();
11 $("input[name=names]:checked").each(function(key, value) { arr[key] = $(value).val(); })
12 $("#msgNames").text("共选中" + arr.length + "项" + arr.join(",")); //注意如果不显示效果时可能是msgNames之前你没有写#
13 });
14 })
15 </script>
16
17 </head>
18 <body>
19 <input type="checkbox" name="names" value="aa" />aa
20 <input type="checkbox" name="names" value="bb" />bb
21 <input type="checkbox" name="names" value="cc" />cc
22 <p id="msgNames">
23 </p>
24 </body>
25 </html>