2012-08-13 87 views
-1

我寫了一個腳本,它在圖像上改變了鼠標上圖像的來源, 起初它的工作,但添加第二個圖像,使用相同的代碼後,都停止工作。Onmouseover OnMouseout javascript

我遇到的問題是圖像不會像鼠標一樣更改。它看起來好像沒有找到圖像 - 但是我確定圖像的來源指向正確的路徑。

我也問過其他意見,我看不出我做錯了什麼。我真的很感激你的幫助或對此的任何意見。

以下是我正在使用的代碼。

<html> 
    <head> 
    <script type="text/javascript"> 
     var images= new Array(); 
     images[0] = "Benjamin/Untitled-3.png"; 
     images[1] = "Benjamin/Untitled-4.png"; 
     images[2] = "Benjamin/Update.png"; 
     images[3] = "Benjamin/Update2.png"; 

     function Change() 
     { 
     document.getElementById("image").src = images[1]; 
     } 

     function GoBack() 
     { 
     document.getElementById("image").src = images[0]; 
     } 

     function GobackAgain() 
     { 
     document.GetElementById("Update").src = images[2]; 
     } 

     function ChangeAgain() 
     { 
     document.getElementById("Update").src = images[3]; 
     } 
    </script> 

    <style type="text/css"> 
     body 
     { 
     background-color:#1c1a1a; 
     } 
    </style> 

    <div align="center"> 
     <img src="Untitled-2.png" width="325" height="191"> 
    </div> 

    </head> 

    <body> 
    <img onmouseover="Change()" 
     onmouseout="GoBack()" 
     id="image" 
     STYLE="position:absolute; TOP:35%; LEFT:10%; WIDTH:204px; HEIGHT:278px" 
     src="Untitled-3.png"> 

    <img onmouseover="ChangeAgain()" 
     onmouseout="GoBackAgain()" 
     id="Update" 
     STYLE="position:absolute; TOP:35%; LEFT:50%; WIDTH:204px; HEIGHT:278px" 
     src="Update.png"> 
    </body> 
</html> 
+2

您的'GobackAgain'包含一個錯誤:'GetElementById'不存在,請使用'getElementById' – Vlad 2012-08-13 21:40:58

+0

哦,對不起,dident發現你的anwser!是的,我改變了,仍然無法正常工作:/快速anwser! – user1596535 2012-08-13 21:49:07

+0

沒問題,請參閱下面的完整答案。 – Vlad 2012-08-13 21:51:02

回答

2

重命名GobackAgainGoBackAgaingetElementById取代GetElementById

+0

沒有訣竅!:s – user1596535 2012-08-13 21:54:10

+0

您也許知道一種替代方法嗎? – user1596535 2012-08-13 22:03:09

+0

你確定嗎?這是你在jsbin中的代碼http://jsbin.com/imiqih/3/edit – Vlad 2012-08-13 22:06:46

0

這裏有一個問題:

function GobackAgain() 
{ 
    document.GetElementById("Update").src = images[2]; 
} 

你有GetElementById當它應該是getElementById

+0

修正了這個問題,但仍然發生同樣的情況!:/ btw感謝您的快速啓動!=) – user1596535 2012-08-13 21:46:15

相關問題