日期:2014-05-16 浏览次数:20408 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JQuery Problem</title>
<script language="javascript" type="text/javascript" src="jquery-ui-1.10.3/jquery-1.9.1.js"></script>
</head>
<body>
<form>
<input type="checkbox" name="_val" value="" /><br />
<input type="checkbox" name="val[]" value="1" />a1<br />
<input type="checkbox" name="val[]" value="2" />b2<br />
<input type="checkbox" name="val[]" value="3" />c3<br />
<input type="checkbox" name="val[]" value="4" />d4<br />
<input type="checkbox" name="val[]" value="5" />e5<br />
<input id="btn" type="button" name="btn" value="Click" />
</form>
<script type="text/javascript" language="javascript">
jQuery(function(){
var keys = new Array();
var boxCheck = {
clickBox:function(){
$("#btn").click(function(){
keys = new Array();
$("input[name^=val]").each(function(i){
if($(this).prop("checked") == true){
//if($(this).val())
keys[i] = $(this).val();
}
});
var len = keys.length;
alert("keys:"+keys+"\n len:"+len);
});
}
} //end boxCheck
boxCheck.clickBox();
});
</script>
</body>
</html>