f_get()
{
a=getElementsByName("q")
for(i=0;i<a.length;i++)
if(a[i].checked)
alert(a[i].value)
}

解决方案 »

  1.   

    首先你的radio寫錯了<form name ="w">
    <input type=radio value=1 name=q checked></input>
    <input type=radio value=2 name=q></input>
    </form>
    <input type=button value=getValue onclick="f_get()">
    <script>
    function f_get()
    {
    var a=document.w;
    for(i=0;i<a.length;i++)
      if(a.elements[i].checked)
        {alert(a.elements[i].value);break;}
    }
    </script>
      

  2.   

    sorry
    f_get()
    {
    a=document.getElementsByName("q")
    for(i=0;i<a.length;i++)
    if(a[i].checked)
    alert(a[i].value)
    }
      

  3.   

    还可以:
    <form name ="w">
    <input type=radio value=1 name=q>
    <input type=radio value=2 name=q>
    </form>
    <script language="JavaScript">
    a=document.w.q
    for(i=0;i<a.length;i++)
    alert(a[i].value)
    </script>