2012-08-13 81 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

相关问题