我有四个radio,内容分别为优秀,良好,一般,差。当选择有货时,这四个radio必须有一个被选中;当选择断货时,这四个radio都不能被选且如果有选中的话要全部清除。
我的控制断货时的JS代码如下:
 document.Form1.A[0].checked = false;
      document.Form1.A[1].checked = false;
      document.Form1.A[2].checked = false;
      document.Form1.A[3].checked = false;      document.Form1.A[0].disabled = true;
      document.Form1.A[1].disabled = true;
      document.Form1.A[2].disabled = true;
      document.Form1.A[3].disabled = true;可是执行时,如果我先选择了优秀,document.Form1.A[0].checked = false;
这句执行没有问题,后面的执行也不会报错。如果我选择了良好,document.Form1.A[0].checked = false;
这句执行通过,但是这句document.Form1.A[1].checked = false;
执行出错“document.Form1.A is undefined”

解决方案 »

  1.   

    alert(document.Form1.A.length)出来结果为5,却是还是提示一样的错
      

  2.   

    你先循环输出document.Form1.A[i].tagName看看是不是获取到了radio了
      

  3.   

    <html><head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("input[type='button']").click(function(){
       $("input[type='radio']").each(function(){
          this.checked = false;
          this.disabled = true;
       });
    });
    });
    </script>
    </head><body>
    </body>
    <input type="radio" name='r1' />1
    <input type="radio" name='r1' />2
    <input type="radio" name='r1' />3
    <input type="radio" name='r1' />4
    <br>
    <input type="button" value='clear' />
    </html> 
      

  4.   

    直接再加一个断货的radio,name值和前面四个的一样就行了
    选中它的话其他的肯定就不会被选中 你得明白radio和checkbox的用法
      

  5.   

    HTML代码如下:
    <tr>
        <td><input type="radio" name="GoodsStatus" id="GoodsStatus1" value="1" onclick="CheckSaleOption1();" />
    有货</td>
         <td rowspan="3"><input type="radio" name="A" id="A1" value="5" />
    优秀
      <input type="radio" name="A"  id="A2" value="4" />
    良好 <br />
    <input type="radio" name="A"  id="A3" value="3" />
    一般
    <input type="radio" name="A"  id="A4" value="2" />
    较差 <br />
    <input type="radio" name="A"  id="A5" value="1" />
    非常差 </td></tr>
            <tr>
        <td><input type="radio" name="GoodsStatus"  id="GoodsStatus2" value="2" onclick="CheckSaleOption2();" />
    断货</td>
      </tr>JS代码如下: <script type="text/javascript">
    function CheckSaleOption1(){
       
          document.Form1.A[0].disabled = false;
          document.Form1.A[1].disabled = false;
          document.Form1.A[2].disabled = false;
          document.Form1.A[3].disabled = false;
          document.Form1.A[4].disabled = false;      
            }
      
        function CheckSaleOption2(){     
          
          document.Form1.A[0].checked = false;       
          document.Form1.A[1].checked = false;     
          document.Form1.A[2].checked = false;
          document.Form1.A[3].checked = false;
          document.Form1.A[4].checked = false;      document.Form1.A[0].disabled = true;
          document.Form1.A[1].disabled = true;
          document.Form1.A[2].disabled = true;
          document.Form1.A[3].disabled = true;
          document.Form1.A[4].disabled = true;       
            }
    </script>
      

  6.   

    <html> 
    <script type="text/javascript">
    function CheckSaleOption1(){
       
          document.Form1.A[0].disabled = false;
          document.Form1.A[1].disabled = false;
          document.Form1.A[2].disabled = false;
          document.Form1.A[3].disabled = false;
          document.Form1.A[4].disabled = false;      
            }    
      
        function CheckSaleOption2(){     
          
          document.Form1.A[0].checked = false;       
          document.Form1.A[1].checked = false;     
          document.Form1.A[2].checked = false;
          document.Form1.A[3].checked = false;
          document.Form1.A[4].checked = false;      document.Form1.A[0].disabled = true;
          document.Form1.A[1].disabled = true;
          document.Form1.A[2].disabled = true;
          document.Form1.A[3].disabled = true;
          document.Form1.A[4].disabled = true;       
            }            
    </script><body>
    <form name="Form1"><!--增加的Form-->
    <table>
    <tr>
    <td>
    <input type="radio" name="GoodsStatus" id="GoodsStatus1" value="1" onclick="CheckSaleOption1();" />有货
    </td>
    <td rowspan="3">
    <input type="radio" name="A" id="A1" value="5" />优秀
    <input type="radio" name="A"  id="A2" value="4" />良好 
    <br />
    <input type="radio" name="A"  id="A3" value="3" />一般
    <input type="radio" name="A"  id="A4" value="2" />较差 
    <br />
    <input type="radio" name="A"  id="A5" value="1" />非常差 
    </td>
    </tr>
    <tr>
    <td>
    <input type="radio" name="GoodsStatus"  id="GoodsStatus2" value="2" onclick="CheckSaleOption2();" />断货
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>