function checkbox(ename){
d = document.all[ename];//被选对象
n = document.getElementsByName(ename).length;
if(n > 1){
   for(i = 0; i < n; i++){
       if(d[i].checked){
       return true;
       }
   }
   }
else {
if(d.checked){
return true;
}
}alert("请选择操作对象!");
return false;}

解决方案 »

  1.   

    不会啊,传错值了吧?
    <input name=haha type=checkbox checked>
    <input name=haha type=checkbox>
    <script language=javascript>
    function checkbox(ename){
    d = document.all[ename];//被选对象
    n = document.getElementsByName(ename).length;
    if(n > 1){
       for(i = 0; i < n; i++){
           if(d[i].checked){
           return true;
           }
    }
    }
    else{
    if(d.checked){
    return true;
    }
    }


    alert("请选择操作对象!");
    return false;}
    alert(checkbox("haha"))
    </script>
      

  2.   

    晕,有两CHECKBOX,取错名字。。汗!
      

  3.   

    checkbox完全允许重名, 当几个checkbox用同个名字时, 它们成为一数组,例如前面那位朋友里边的两个name=haha就可以用haha[0],haha[1]得到。楼主是不是要做一个这样的效果: 
    当所有checkbox都没有选中, 提示“请选择操作对象”?
    如果是的, 试试看下面的效果对你有无用(还是用自己平时习惯书写舒服一点^_^)<script language=javascript>
    function checkbox(){
    var checkValue = false;
    for(i=0; i<document.testform.chkbox.length; i++){     
    if(document.testform.chkbox[i].checked == true){
    checkValue = true;
    }
    }

    if(checkValue == false){
    alert("请选择操作对象!");
    }
    else{
    alert("OK");
    }
    }
    </script><form name="testform" method="post">
    <input type="checkbox" name="chkbox" >
    <input type="checkbox" name="chkbox" >
    <input type="checkbox" name="chkbox" >
    <input type="button" name="btn" value="Btton" onclick="checkbox()" />
    </form>