jQuery 判断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=utf-8" />
<title>jquer01_01</title>
<script src="../jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":checkbox").click(function(){
var $checkArray = $(":checkbox").toArray();
var $check=0;
$.each($checkArray,function(key,val){
if(val.checked){
$check++;
}
});
if($check==$checkArray.length){
$("#submitbtn").removeAttr("disabled");
}else{
$("#submitbtn").attr({"disabled":"disabled"});
}
});
});
</script>
</head>
<body>
<input type="checkbox" name="Term"/>
<input type="checkbox" name="Term"/>
<input type="checkbox" name="Term"/>
<input type="checkbox" name="Term"/>
<input id="submitbtn" type="button" value="同意" class="agrbtn" disabled="disabled"/>
</body>
</html>
本文介绍了一种使用jQuery实现的方法,用于判断页面上的所有Checkbox是否被全部选中。当所有Checkbox都被选中时,将启用提交按钮;若任一未被选中,则禁用提交按钮。此方法适用于网页表单验证场景。
363

被折叠的 条评论
为什么被折叠?



