2016-11-15 43 views
1

我正在嘗試製作使用HTML,JavaScript和CSS的網頁,但我的圖像文件不會顯示。我在與HTML文件相同的文件夾中有我的img文件夾。 我想顯示未修飾的樹,然後當用戶單擊按鈕以顯示其他圖像,但它只顯示圖像alt消息。無法顯示HTML文件中的圖像

<!DOCTYPE html>       
<html> 
<title> 
Christmas 
</title> 
<body> 
<h1>Lets decorate this chritmas tree!</h1> 

<button onclick="document.getElementById('xmasTreeImage').src='decoratedtree.jpg'">Decorate the tree</button> 
<img id="xmasTreeImage" alt="Can't display" src="undecoratedtree.jpg" style="width:100px"> 
<button onclick="document.getElementById('xmasTreeImage').src='undecoratedtree.jpg'">Take away the decorations</button> 

</body> 
</html> 

更新:

<!DOCTYPE html>       
<html> 
<title> 
Christmas 
</title> 
<body> 
<h1>Lets decorate this chritmas tree!</h1> 


<button onclick="document.getElementById('xmasTreeImage').src='C:\Users\Me\Documents\ChristmasWebProject/decoratedtree.jpg'">Decorate the tree</button> 
<img id="xmasTreeImage" alt="Can't display" src="C:\Users\Me\Documents\ChristmasWebProject/undecoratedtree.jpg" style="width:100px"> 
<button onclick="document.getElementById('xmasTreeImage').src='C:\Users\Me\Documents\ChristmasWebProject/undecoratedtree.jpg'">Take away the decorations</button> 

</body> 
</html> 

如果我在它顯示的圖像精確的目錄添加,但肯定有一種更有效的方式來做到這一點?它也不顯示任何東西,當我點擊按鈕之前它只顯示圖像。

+0

在這裏你需要檢查這個圖像的路徑。是否正確裝載器或不? –

+0

是的,它和HTML文件位於同一個目錄@caramba – Jill

+0

你可以打開並保存圖片嗎?不經常發生,但檢查圖像文件的權限。或者將圖像拖放到瀏覽器中,然後僅用於從HTML文件中複製/粘貼URL中的路徑。 – caramba

回答

0

我能夠通過在特定目錄中鍵入來顯示圖像。看到我的問題編輯代碼。