2013-05-04 68 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