<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script type="text/javascript"> 
//这里的javascript是来控制radiobutton默认选择值为A的Radio的,总是不能实现,郁闷 .....
function  test()
{
    for(i=0;i<document.RadioGroup1.length();i++)
{
   if (document.getElementByName("RadioGroup1").value=='A')
   document.getElementByName("RadioGroup1").value = true;
}
 
}
</script><body>
<form id="form1" name="form1" method="post" onsubmit="test();">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="A" />
      A</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="V" />
      B</label>
    <label>
    <input type="submit" name="Submit" value="提交" />
    </label>
    <br />
  </p>
</form>
</body>
</html>

解决方案 »

  1.   

    onsubmit="return test();"
    用document.form1.RadioGroup1[i]引用
    document.form1.RadioGroup1[i].checked = true;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript"> 
    function  test()
    {
        for(i=0;i<document.form1.RadioGroup1.length;i++)
        {
           if (document.form1.RadioGroup1[i].value=='A') document.form1.RadioGroup1[i].checked = true;
        }
     return false;
    }
    </script><body>
    <form id="form1" name="form1" method="post" onsubmit="return test();">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="A" />
          A</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="V" />
          B</label>
        <label>
        <input type="submit" name="Submit" value="提交" />
        </label>
        <br />
      </p>
    </form>
    </body>
    </html>
      

  2.   

     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript"> 
    //楼上大哥,为啥我写到程序中就实现不了选中呢,这是我写的
    function  test()
    {
        for(i=0;i<document.form1.shipping.length();i++)
    {
       
       if (document.form1.shipping[i].value=='FedexRush_FedexRush')
       document.form1.shipping[i].checked = true;
    }
     return false;
    }
    </script><body>
    <form id="form1" name="form1" method="post" onsubmit="return test();">
      <p>
        <label>
          <input type="radio" name="shipping" value="FedexExpress_FedexExpress" CHECKED>
            FedexExpress_FedexExpress
    </label>
        <br />
        <label>
        <input type="radio" name="shipping" value="FedexRegular_FedexRegular" CHECKED>
          FedexRegular_FedexRegular
    </label>
    <br />
        <label>
    <input type="radio" name="shipping" value="FedexRush_FedexRush" CHECKED>
    FedexRush_FedexRush
        </label>
    <br />
    <label>
    <input type="radio" name="shipping" value="usps_usps" CHECKED>
    usps_usps
        </label>
     <input type="submit" name="Submit" value="提交" />
        <br />
      </p>
    </form>
    </body>
    </html>
      

  3.   

    document.getElementsByName("RadioGroup1") //document.getElementsByName,LZ漏了s
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript"> 
    function  test()
    {
        var radio = document.getElementsByName("RadioGroup1");
        for(i=0;i<radio.length;i++)
        {
           if (radio[i].value=='A') 
               radio.checked = true;
        }
        return true;
    }
    </script><body>
    <form id="form1" name="form1" method="post" onsubmit="return test();">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="A" />
          A</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="V" />
          B</label>
        <label>
        <input type="submit" name="Submit" value="提交" />
        </label>
        <br />
      </p>
    </form>
    </body>
    </html>
      

  5.   

    不好意思,上面写错了一处,更正后<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript"> 
    function  test()
    {
        var radio = document.getElementsByName("RadioGroup1");
        for(i=0;i<radio.length;i++)
        {
           if (radio[i].value=="A") 
               radio[i].checked = true;
        }
        return true;
    }
    </script><body>
    <form id="form1" name="form1" method="post" onsubmit="return test();">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="A" />
          A</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="V" />
          B</label>
        <label>
        <input type="submit" name="Submit" value="提交" />
        </label>
        <br />
      </p>
    </form>
    </body>
    </html>