js 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>js checkbox 是否选中并限制选中个数</title>
<script language="网页特效">
function checkboxnum(){
var form = document.forms['dataform'];
var i,j=0;
for (i=0; i<form.length; i++){
var e=form[i];
if (e.checked && e.type=='checkbox' && e.name=='house_feature[]') {
j++;
if(j==4){
alert("最多只能选择3项!");
return false;
break;
}
}
}
}
</script>
</head><body>
<form id="dataform" name="dataform" action="" method="post">
<input type="checkbox" name="house_feature[]" id="house_feature_1" value="1" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_2" value="2" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_3" value="3" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_4" value="4" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_5" value="5" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_6" value="6" onclick="return checkboxnum()" />
<input type="checkbox" name="house_feature[]" id="house_feature_7" value="7" onclick="return checkboxnum()" />
</form>
</body>
</html>