时间:2021-05-03 10:01:44 | 栏目:jquery | 点击:次
实例如下:
<SCRIPT LANGUAGE="JavaScript"> //判断同类型 function checkboxnum(){ var form = document.forms['formbj1']; var i,j=0; for (i=0; i<form.length; i++){ var e=form[i]; if (e.checked && e.type=='checkbox' && e.name=='bjid[]') { j++; if(j==3){ alert("最多只能选择2项!"); return false; break; } } } } </script> <form action="zhdk_bj.php" method="post" name="formbj1" id="formbj1"> <input name="bjid[]" id="bjid[]" type="checkbox" onclick="return checkboxnum()" value="1" /> <input name="bjid[]" id="bjid[]" type="checkbox" onclick="return checkboxnum()" value="2" /> <input name="bjid[]" id="bjid[]" type="checkbox" onclick="return checkboxnum()" value="3" /> </form>