Home > Article > Web Front-end > How to implement javascript to pop up a warning box when the check box exceeds the limit_javascript skills
The example in this article describes the method of using JavaScript to pop up a warning box when the check box exceeds the limit. Share it with everyone for your reference. The specific implementation method is as follows:
<html> <title>javascript实现复选框超过限制即弹出警告框的方法</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>
I hope this article will be helpful to everyone’s JavaScript programming design.