2013-05-04 67 views
0

我想创建一个简单的图像库与单选按钮。图像设置为显示:无;默认。我想要的是他们显示为块时,我点击各自的按钮。简单的图像库JS

<html> 
<head> 
    <style> 
     .img { width: 250px; 
       max-height: 300px; 
       display: none; 
     } 
    </style> 
    <script> 
     function picture (a) { 
      var pic = document.getElementById('image') 
      if (a == 1) { 
       pic.src="julia1.jpg" 
      } else { pic.src="julia2.jpg"} 

      pic.style.display ="block"; 
     } 

    </script> 
</head> 
<body> 
    <img class="img" id="image" src="julia1.jpg"> 
    <form action=""> 
     <input type="radio" onclick="picture(1)" name="picture"></input> 
     <input type="radio" onclick="picture(2)" name="picture"></input> 
    </form> 
</body> 
</html> 

在浏览器控制台上,它表示该对象不是函数。那是什么意思? (那两个输入变量)

回答

0

最后一行应改为

pic.style.display = "block"; 
+0

是没有做它 – 2013-05-04 23:07:10

+0

功能和输入元素不应该被命名为相同。 – 2013-05-04 23:12:35

+0

非常感谢,那是我的一个愚蠢的错误。 – 2013-05-04 23:17:06