Home  >  Article  >  Web Front-end  >  How to implement javascript to pop up a warning box when the check box exceeds the limit_javascript skills

How to implement javascript to pop up a warning box when the check box exceeds the limit_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:13:111448browse

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 &#63; 1 : 0) + (box2 &#63; 1 : 0) + (box3 &#63; 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn