function mincount()
{
    var y = 0;
    var softitems = document.getElementsByName("softitem");
    if (softitems != null)
    {
        for (var j = 0; j < softitems.length; j++)
        {
            if (softitems[j].checked == true)
                y++;
        }
        if (y < 1)
        {
            alert("抱歉请最少选择一个!");
            return false;
        }
    }
} 改成这样

解决方案 »

  1.   

    你复选框的代码是怎么写的?我把你的代码做个测试是可以用的,"抱歉请最少选择一个"是可以弹出来的.
    <input type="checkbox" id="a" name="softitem" onclick="count();mincount()" checked>a
    <input type="checkbox" id="b" name="softitem" onclick="count();mincount()">b
    <input type="checkbox" id="c" name="softitem" onclick="count();mincount()">c
    <input type="checkbox" id="d" name="softitem" onclick="count();mincount()">d<script type=text/javascript>
    function count(){
       var x=0;
       var softitem = document.getElementsByName("softitem");
       if(softitem!=null){
          for(var i=0;i<softitem.length;i++){
             if(softitem[i].checked==true)x++;
             if(x>2){
                 alert("抱歉,最多只能选2个!");
                 return false;
             }
          }
       }
    }
    function mincount(){
       var y=0;
       var softitems = document.getElementsByName("softitem");
       if(softitems!=null){
          for(var j=0;j<softitems.length;j++){
             if(softitems[j].checked==true)y++;
             if(y<1){
                 alert("抱歉请最少选择一个!");
                 return false;
             }
          }
       }
    }
    </script>