<SCRIPT  type="text/javascript">
function showPic() {
var a=document.getElementsByName('radio');
if(a.checked)
{
document.write("<img src='3.png' />");

       }
</SCRIPT> 
点击单选按钮后图片不显示

解决方案 »

  1.   

    var a=document.getElementsByName('radio')[0];
    试试
      

  2.   

    var a=document.getElementsByName('radio');这里的a是一个数组,楼上那样写就能显示你要的效果,不过只有在选择第一个时会显示你要的效果
      

  3.   

    你既然是单选按钮的click事件,你如果对每一个项都设置了 onclick="showPic()"的话,你应该变更为:onclick="showPic(this)",你如果没有其他事件,你甚至连选中状态都不必检测吧,单选按钮,你没其他事件判断选择项的话,你鼠标一点,它还不选中?<SCRIPT type="text/javascript">
    function showPic(o) {
    if(o.checked)
    {
    alert(o.value);
    }  
      }
    </SCRIPT> 你如果没有单独的绑定事件,那你可以使用window.onload去批量绑定相关事件
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>测试</title>
    <script type="text/javascript">
    window.onload=function(){
        var o=document.getElementsByName("r1");
        for(i=0;i<o.length;i++)
        {
            o[i].onclick=function(){
                alert("你选中了"+this.value);
            }
        }
    }</script>
    </head>
    <body>
    <input type="radio" name="r1" checked="checked" value="1"/>
    <input type="radio" name="r1" value="2"/>
    <input type="radio" name="r1" value="3"/>
    <input type="radio" name="r1" value="4"/>
    <input type="radio" name="r1" value="5"/>
    <input type="radio" name="r1" value="6"/>
    <input type="radio" name="r1" value="7"/>
    <input type="radio" name="r1" value="8"/>
    <input type="radio" name="r1" value="9"/>
    <input type="radio" name="r1" value="10"/>
    </body>
    </html>