<form action="" method="post" name="voteform" id="voteform" onsubmit="return Check();">
<table>
   <tr>
        <td width="75"></td>
        <td colspan="4" class="votetitle" height="18">A</td>
    <tr>
    <tr>
     <td width="75"></td>
     <td width="140"><input type="checkbox" name="conditions[]" value="1" />1</td>
        <td width="140"><input type="checkbox" name="conditions[]" value="2" />2</td>
        <td width="140"><input type="checkbox" name="conditions[]" value="3" />3</td>
        <td width="140"><input type="checkbox" name="conditions[]" value="4" />4</td>
    </tr>
    
        <tr>
        <td width="75"></td>
        <td colspan="4" class="votetitle" height="18">B</td>
    <tr>
    <tr>
     <td width="75"></td>
     <td width="140"><input type="checkbox" name="hstyle[]" value="1" />1</td>
        <td width="140"><input type="checkbox" name="hstyle[]" value="2" />2</td>
        <td width="140"><input type="checkbox" name="hstyle[]" value="3" />3</td>
        <td width="140"><input type="checkbox" name="hstyle[]" value="4" />4</td>
    </tr>
    <tr><td colspan="5" height="15"></td></tr>
        <tr>
        <td colspan="5" class="votetitle" height="18" align="center"><input  type="submit" name="submit" value="提交"/></td>
    <tr> 
</table>
</form>本来想弄个调查表,但是这里不知道怎么判断,每个标题下有好几个选项 ,选项都是多选的 !
麻烦高手指导一下 谢谢 !~~

解决方案 »

  1.   

    var conditions=document.getElementByName("conditions[]");
    for(var i=0;i<condition.length;i++){
        if(condition[i].checked=true)
           ; //do something
    }那一个也类似
      

  2.   

    不行啊 
    测试了 没反应 。。<script>
    function  Check(){
    var cond=document.getElementByName("conditions[]");
    for(var i=0;i<cond.length;i++){
      if(conditions[i].checked=true)  
      alert("吓死爹啊");  
    }
    }
    </script>是这个样子吗??
      

  3.   

    或者if(condition[i].checked=="checked")试试  不知为什么  有时候true可以用  有时候"checked"才能正常工作   不知是不是浏览器的问题  呵呵
      

  4.   

    <form action="" method="post" name="voteform" id="voteform" onsubmit="return Check();">
    <table>   <tr>
            <td width="75"></td>
            <td colspan="4" class="votetitle" height="18">NAME:<input type="text" name="name" /></td>
        <tr>
       <tr>
            <td width="75"></td>
            <td colspan="4" class="votetitle" height="18">A</td>
        <tr>
        <tr>
            <td width="75"></td>
            <td width="140"><input type="checkbox" name="conditions[]" value="1" />1</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="2" />2</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="3" />3</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="4" />4</td>
        </tr>
        
        <tr>
            <td width="75"></td>
            <td colspan="4" class="votetitle" height="18">B</td>
        <tr>
        <tr>
            <td width="75"></td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="1" />1</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="2" />2</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="3" />3</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="4" />4</td>
        </tr>
        <tr><td colspan="5" height="15"></td></tr>
            <tr>
            <td colspan="5" class="votetitle" height="18" align="center"><input  type="submit" name="submit" value="提交"/></td>
        <tr> 
    </table>
    </form>
    <script>
    function  Check(){if (document.voteform.name.value == ""){

    alert("想吓死爹啊 ");
    document.voteform.name.focus();
    return false;
    }

    var cond=document.getElementByName("conditions[]");
    for(var i=0;i<cond.length;i++){
      if(conditions[i].checked == "checked" || conditions[i].checked == true)  
      alert("吓死爹啊");  
    }
    }
    </script>这是我测试的 我加了一个 name 测试一下可以  就是 checkbox 没什么反应 ,你们可以试试 ,我用的firefox !~ 谢谢了 
      

  5.   

    <html>
    <head>
    <script>
    function Check(form){
    var obj = form.elements["conditions[]"];
    var arr = [];
    arr.push("conditions[]: "); for(var i = 0; i < obj.length; i++){
    if(obj[i].checked){
    arr.push(obj[i].value);
    }
    } var obj1 = form.elements["hstyle[]"];
    arr.push("          hstyle[]: ");
    for(var i = 0; i < obj1.length; i++){
    if(obj1[i].checked){
    arr.push(obj1[i].value);
    }
    } alert(arr.join(","));
    return false;
    }
    </script>
    </head><body>
    <form action="" method="post" name="voteform" id="voteform" onsubmit="return Check(this);">
    <table>
       <tr>
            <td width="75"></td>
            <td colspan="4" class="votetitle" height="18">A</td>
        <tr>
        <tr>
            <td width="75"></td>
            <td width="140"><input type="checkbox" name="conditions[]" value="1" />1</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="2" />2</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="3" />3</td>
            <td width="140"><input type="checkbox" name="conditions[]" value="4" />4</td>
        </tr>
        
            <tr>
            <td width="75"></td>
            <td colspan="4" class="votetitle" height="18">B</td>
        <tr>
        <tr>
            <td width="75"></td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="1" />1</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="2" />2</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="3" />3</td>
            <td width="140"><input type="checkbox" name="hstyle[]" value="4" />4</td>
        </tr>
        <tr><td colspan="5" height="15"></td></tr>
            <tr>
            <td colspan="5" class="votetitle" height="18" align="center"><input  type="submit" name="submit" value="提交"/></td>
        <tr> 
    </table>
    </form>
    </body>
    </html>
      

  6.   

    var cond=document.getElementsByName("conditions[]");firebug 可以调试js 的
      

  7.   

    <script type="text/javascript">
    function ch(){
    var a=document.getElementsByName("s");
    for(var i=0;i<a.length;i++){
    if(a[i].checked==true||a[i].checked=="checked"){
    alert(i);
    }
    }
    }
    </script>
    </head><body>
    <input type="checkbox" name="s">
    <input type="checkbox" name="s">
    <input type="checkbox" name="s">
    <input type="checkbox" name="s">
    <input type="checkbox" name="s">
    <input type="checkbox" name="s">
    <input type="button" id="test" onclick="ch()">
    </body>
    这样写了一个 ie和火狐都可以啊
      

  8.   

    经过各位的帮助 和 楼主的坚持不懈的钻研 这个问题已经基本搞定 而且已经得知在8楼出现之前为什么各位大神的代码不起作用的原因了 
    现在总结一下
    也为以后小菜做点贡献 !
    第一 :2楼var = document.getElementByName("conditions[]"); 中 getElementByName少了一个s 而且 在 for 循环中 condition.length 以及 condition[i].checked=true;中都少了一个s并少了一个等号;而且所以导致楼主 代码一直没通过测试!
    所以 2楼的最终代码如下已经测试通过 <script>
            function  Check(){        
    var num = document.getElementsByName("conditions[]") ;        for(var i=0;i<num.length;i++){
              if(num[i].checked == true)  
              alert("吓死爹啊");  
            }
            }
        </script>第二 楼主之前写的 document.voteform.getElementsByName("conditions[]") 不行;
    看了8楼大婶的 随改成document.voteform.elements.["conditions[]"]通过了;
    所以第二种是这样: <script>
            function  Check(){        
    var num = document.voteform.elements.["conditions[]"];          for(var i=0;i<num.length;i++){
              if(num[i].checked == true)  
              alert("吓死爹啊");  
            }
            }
        </script>当然 8楼 大婶完全可以使用 谢谢 8楼指点迷津啊!~~