练习,遍历复选框
1 <%@ page language="java" import="java.util.*" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 4 <html> 5 <head> 6 <title>11</title> 7 <script type="text/javascript" src="js/jquery-1.11.0.js"> 8 </script> 9 <script language="javascript"> 10 $(document).ready(function() 11 { 12 //***********************获取选中复选框的内容及个数******** 13 $('#bt1').click(function(){ 14 $obj=$("input[type='checkbox']:checked");//$obj是集合($obj[0],$obj[1],$obj[2],$obj[3]) 15 //使用jquery的each方法 16 $.each( $obj, function(i, obj){ 17 alert("obj的长度为"+$obj.length+";obj.value获取为"+obj.value); 18 }); 19 }); 20 }); 21 22 //****************************************************** 23 </script> 24 </head> 25 <body> 26 <input type="button" id="bt1" value="获取所选择的checkbox内容及个数" ></input> 27 <br/><br/> 28 <input type="checkbox" value="篮球">篮球</input> 29 <input type="checkbox" value="乒乓球">pingpang球</input> 30 <input type="checkbox" value="足球"> zu球</input> 31 <br> 32 </body> 33 </html>