日期:2014-05-16  浏览次数:20374 次

jQuery 1.6+ 以后 checkbox的问题
本帖最后由 dmtnewtons 于 2013-09-02 17:53:46 编辑
checkbox选中状态的总长度 和 实际的长度 不一致?
有关选中的版本问题,参考此处

<!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>


示例描述:
如上示例中,如果选中2、3,点击button时,实际长度应为2,但是,alert输出的为3?
判断非空仍不管用。
jQuery checkbox checked