radio肯定只有一个值嘛

if(docuument.form.userName.value==0)就可以了

解决方案 »

  1.   

    radio啊,对,只有一个值,判断应该是==
      

  2.   

    如果是表单的话,
    应该是
    if (document.form.Username[0].checked=="true"){
        }
    这个的话应该是
    if (document.all.Username[0].checked=="true"){
    }
      

  3.   

    <html>
    <head>
    <title>hello</title>
    <body>
    <input type=radio name=UserName value=0 onclick="onchange();">
    <input type=radio name=UserName value=1>
    </form>
    </body>
    </head>
    </html>
    <script>
    function onchange()
    {
    if(document.UserName.value==0)
    alert("hello");
    else
    alert("you are welcome");
    }
    </script>
    这个程序是有两个radio,选第一个出"hello",选第二个出"you are welcome",但运行有错误,望高手赐教!
      

  4.   

    这个问题请参考:http://www.csdn.net/Expert/TopicView1.asp?id=915817第24解
      

  5.   

    function getCheckedRadioNum()
    {
        for (var i=0;i<document.form.userName.length;i++)
            if (document.form.userName[i].checked==1)
                  return i;
            else
                  return -1;
    }
      

  6.   

    谢谢meizz(梅花雨),你提供的程序能运行,可是我想响应radio的点击事件,我根据你提供的程序作了修改,可还是不行,不知道radio控件响不响应onclick
    事件,请帮我把程序改正确,谢谢!:
    <html>
    <head>
    <title>hello</title>
    <script language="vbscript">
    function checkme()
    for each ob in UseName
    {
    if ob.checked then
    alert("hello");
    else
    alert("you are welcome");
    }
    next
    end function
    </script>
    <body>
    <input type=radio name=UserName value=0 onclick="checkme()">
    <input type=radio name=UserName value=1>
    </body>
    </head>
    </html>  
      

  7.   

    richardluopeng(罗罗) :数组好象不对呀,你举个简单例子吧
      

  8.   

    给你一个例子,看看你就明白了 <html>
    <script>
     function ck()
     {document.form1.checkbox[0].click();
     document.form1.checkbox[2].click();  }
    </script>
    <body>
    <form name=form1>
    <input type=checkbox name=checkbox onclick="alert('34');">
    <input type=checkbox name=checkbox > 
    <input type=checkbox name=checkbox onclick="alert('34');"><input type=button onclick=ck();>
    </form>
    </body>
    </html>