您的位置:首页 > 其它

复选框控制超过限制即弹出警告框

2015-07-02 15:15 453 查看
<html>
<title>复选框限制,超过限制即弹出警告框丨任e行行车记录仪</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>
<br><br><hr>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: