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

<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>
    

 

posted @ 2015-07-02 15:15  滇时尚  阅读(159)  评论(0编辑  收藏  举报