斑竹大人请手下留情,我以人格担保此举绝对不是倒分!问题解决了,答应给的分总应该给吧!解决问题:http://www.csdn.net/Expert/TopicView1.asp?id=992222

解决方案 »

  1.   

    当你的radio只有一个的时候,你的程序及其它两位的程序都会出错,因为当只有一个的时候,这个radio已经不再是一个数组了,所以他们两位及你的代码都会出错,不信你拿掉其它的radio只剩下一个试试就知道了。
        所以这里要用到另一个方法:
    <script language=javascript>
    function getRadioValue(RadioName)
    {
      var aa = document.getElementsByName(RadioName)
      for (var i=0; i<aa.length; i++)
      {
         if(aa[i].checked){alert(aa[i].value);return;}
      }
      alert("你一个都没有选择!");
    }
    </script>
      

  2.   

    一般情况下radio 都不会只使用一个(一个可以使用checkbox),当然如果坚持使用一个radio可用以下function :
    !doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
    <script language="JavaScript">
    <!--
    function getRadioValue(place){
      var objRadio = document.forms[0].elements[place];
      var strValue = objRadio.value;
      if (strValue != undefined){
        if (objRadio.checked){
          return strValue;
        }
        else{
          return null;
        }
      }
      for(i=0;i<objRadio.length;i++){
        if(objRadio[i].checked){
          return objRadio[i].value;
        }
      }
      return null;
    }
    //-->
    </script>
    </head><body>
    <form name="form1" method=post action="">
    <!--<input type="radio" name="radioBtn" value="ok">ok<br>-->
    <input type="radio" name="radioBtn" value="nok">not ok<br>
    <input type="button" name="showvalue" value="Show Value" onclick="alert(getRadioValue('radioBtn'))">
    </form>
    </body>
    </html>
      

  3.   

    barrydiu(巴索):
    这句在5.0下会出错
    strValue != undefined这样判断就好了:
    if(objRadio.value){
     if (objRadio.checked){
          return strValue;
     }
    }
      

  4.   

    1.
    <script>
    function getall(){
    var i;
    var es = document.frmSearchUser.elements ;
    for(i=0;i<es.length;i++){
    if (es[i].type=="radio"&&es[i].checked)
    alert(es[i].value) ;
    }
    }
    </script>
    <form name="frmSearchUser">
     <input type="radio" name="attr_0_Oper" value=">=" checked >
     &gt;= 
     <input type="radio" name="attr_0_Oper" value="=" >
     = 
     <input type="radio" name="attr_0_Oper" value="<" >
     &lt; 
     <input type="radio" name="attr_0_Oper" value="<>" >
     &lt;&gt; 
     <input type="radio" name="attr_0_Oper" value="between" >
     between </td>
     <input type="button" name="button" value="button" class="botton" onclick="getall()">
    </form>2.
    <script>
    function getall(){
    var i;
    var es = document.all.tags("input") ;
    for(i=0;i<es.length;i++){
    if (es[i].type=="radio"&&es[i].checked)
    alert(es[i].value) ;
    }
    }
    </script>
    <form name="frmSearchUser">
     <input type="radio" name="attr_0_Oper" value=">=" checked >
     &gt;= 
     <input type="radio" name="attr_0_Oper" value="=" >
     = 
     <input type="radio" name="attr_0_Oper" value="<" >
     &lt; 
     <input type="radio" name="attr_0_Oper" value="<>" >
     &lt;&gt; 
     <input type="radio" name="attr_0_Oper" value="between" >
     between </td>
     <input type="button" name="button" value="button" class="botton" onclick="getall()">
    </form>3.
    <script>
    function getall(){
    var i;
    var es = document.frmSearchUser.attr_0_Oper ;
    if (es.length)
    for(i=0;i<es.length;i++){
    if (es[i].checked)
    alert(es[i].value) ;
    }
    else
    if (es.checked)
    alert(es.value) ;
    }
    </script>
    <form name="frmSearchUser">
     <input type="radio" name="attr_0_Oper" value=">=" checked >
     &gt;= 
     <input type="radio" name="attr_0_Oper" value="=" >
     = 
     <input type="radio" name="attr_0_Oper" value="<" >
     &lt; 
     <input type="radio" name="attr_0_Oper" value="<>" >
     &lt;&gt; 
     <input type="radio" name="attr_0_Oper" value="between" >
     between </td>
     <input type="button" name="button" value="button" class="botton" onclick="getall()">
    </form>
      

  5.   

    to fokker(独孤龙) :
    我在ie5.0 和nescape 4.79下测过,没有问题阿。
    你能不能贴一下报错信息。你的方法很好,ie和NN都ok.
      

  6.   

    barrydiu(巴索):
    你的浏览器有没有禁止脚本调试?
    这是我以前发现的,现在手头上没有ie5.0的机器。我记得好像是说,undefined未定义
      

  7.   

    to fokker(独孤龙) :
    你的意见是对的,不能用strValue != "undefined" 或strValue != undefined我想我的浏览器没有报错是因为我装过ie6.