<html>
<title>
复选框超过限制即弹出警告框 - www.xingzuo51.com</title>
<body>
<SCRIPT LANGUAGE="
javascript">
<!--//
function countChoices(obj) {
max = 2;
box1 = obj.form.box1.
checked;
box2 = obj.form.box2.checked;
box3 = obj.form.box3.checked;
count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0);
if (count > max) {
alert("对不起,你只能选择" + max + "个项目!");
obj.checked = false;
}
}
//-->
</script>
<form name="form">
请最多选择2个项目:
<p>
<input type=
checkbox name=box1 onClick="countChoices(this)">
选择项目1
<p>
<input type=checkbox name=box2 onClick="countChoices(this)">
选择项目2
<p>
<input type=checkbox name=box3 onClick="countChoices(this)">
选择项目3
<p>
<div>
</div>
</form>
</body>
</html>