我想有2 按鈕或只是2個標籤或喜歡顯示/隱藏2 imges但彼此獨立。我已經編碼爲1圖像,但它現在不工作,如果我將它設置爲兩次在HTML中。見JSFiddle。如何在html中獲取按鈕以顯示/隱藏圖像?
HTML:
<html>
<head>
<title></title>
</head>
<body>
<p><img height="600" id="map_img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Hsi-h000.png/600px-Hsi-h000.png" style="display: none;" width="600" /> <input id="Mapred" onclick="showImg()" type="submit" value="Mapred" /></p>
<p><img height="800" id="map_img2" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Sandro_Botticelli_-_La_nascita_di_Venere_-_Google_Art_Project_-_edited.jpg/800px-Sandro_Botticelli_-_La_nascita_di_Venere_-_Google_Art_Project_-_edited.jpg" style="display: none;" width="502" /> <input id="Map" onclick="showImg2()" type="submit" value="Map" /></p>
</body>
</html>
你能分享工作的代碼? –
[Jquery:單擊按鈕顯示/隱藏菜單]的可能重複(http://stackoverflow.com/questions/23322039/jquery-show-hide-menu-with-single-button) –
您應該將其更改爲'樣式.display =「none」;''和'「block;」'否則 –