可以改成:
var obj = document.getElementsByName("type"+i);

解决方案 »

  1.   

    var obj = eval("document.form1.type" + i);
      

  2.   

    你打印:
    var obj=document.form1.("type"+i).length
    你发现问题在哪了
      

  3.   

    var obj=document.forms["form1"]["type"+i]; 
      

  4.   

    给出的代码都是错的,我给改了一下<script>
    function getvalue(i){
        var obj=document.forms["form1"]["type"+i]; 
      for(j=0;j <3;j++){
          if(obj[j].checked){
              var value=obj[j].value;
              break;
          }
      }
    alert(value)
      return value;
    }
    </script>
        <form name=form1>  <input type="radio" name='type0' value=1 />  <input type="radio" name='type0' value=2 />  <input type="radio" name='type0' value=3 />  <input type="radio" name='type1' value=1 />  <input type="radio" name='type1' value=2 />  <input type="radio" name='type1' value=3 />  <input type="radio" name='type2' value=1 />  <input type="radio" name='type2' value=2 />  <input type="radio" name='type2' value=3 /></form><button onclick="getvalue(0)">getvalue</button>
      

  5.   

    用eval()。var obj=eval("document.form1.type"+i); 
    <form name=form1>
       <input type="radio" name='type0' value=1 />01</input>
       <input type="radio" name='type0' value=2 />02</input>
       <input type="radio" name='type0' value=3 />03</input>    <input type="radio" name='type1' value=1 />11</input>
       <input type="radio" name='type1' value=2 />12</input>
       <input type="radio" name='type1' value=3 />13</input>    <input type="radio" name='type2' value=1 />21</input>
        <input type="radio" name='type2' value=2 />22</input>
        <input type="radio" name='type2' value=3 />23</input>
    <button onclick="alert(getvalue(0))">确定</button>
    </form>
    <script language=javascript>function getvalue(i)

        var obj=eval("document.form1.type"+i); 
        for(j=0;j <3;j++)
        { 
          if(obj[i].checked)
          { 
              var value = obj[i].value; 
              break; 
          } //if
        } //for 
      return value; 
    } </script>

      

  6.   

    简洁高效<script language="javascript" type="text/javascript">
    function getvalue(i){ 
    for(var j=0;j<3;j++)
    {
    var o=document.getElementsByName("type"+i)[j];
    if (o.checked)
          alert(o.value);
            else
                  alert("还没有选择");
    }

    </script>
    <form name=form1>
       <input type="radio" name='type0' value=1 />
       <input type="radio" name='type0' value=2 />
       <input type="radio" name='type0' value=3 />
    <input type="button" name="Submit" value="按钮1" onClick="javascript:getvalue(0);">
        <input type="radio" name='type1' value=1 />
       <input type="radio" name='type1' value=2 />
       <input type="radio" name='type1' value=3 />
    <input type="button" name="Submit" value="按钮2" onClick="javascript:getvalue(1);">
        <input type="radio" name='type2' value=1 />
       <input type="radio" name='type2' value=2 />
       <input type="radio" name='type2' value=3 />
    <input type="button" name="Submit" value="按钮3" onClick="javascript:getvalue(2);">
    </form>