javascript中的onmouseover和onmouseout事件

时间:2015-01-10 06:43:46

标签: javascript javascript-events

我是javasript的新手 我有简单的代码,在谷歌chroome工作正常,但剧本din't firefox 它只是关于onmouseover和onmouseout的两个事件并且更改图像

<!DOCTYPE html>
<html>
<head>
    <title> </title>
    <script>

        function over() {
        image1.src = "13.JPG"
              }


        function out() {
        image1.src = "19.JPG"
              }
    </script>

    <style>
        img {
        height:200px; width:200px;
        }
    </style>

</head>
<body>

    <img  id="image1" onmouseover="over()" onmouseout="out()" />

</body>
</html>

它在谷歌chroome中运行良好,但在firefox中没有,我想知道原因,谢谢。

1 个答案:

答案 0 :(得分:0)

以下是如何使用javascript:

执行此操作

&#13;
&#13;
function over() {
        document.getElementById('image1').src = "http://animalrescuetracy.org/wp-content/uploads/2014/07/playful-kitten-6683.jpg";
}


function out() {
        document.getElementById('image1').src  = "http://www.valleyvet.com/images/worming-your-kitten.png";
 }
&#13;
img {
        height:200px; width:200px;
        }
&#13;
<img  id="image1" src="" onmouseover="over()" onmouseout="out()"/>
&#13;
&#13;
&#13;

以下是如何使用css:

&#13;
&#13;
#image1{
	content:url("http://www.valleyvet.com/images/worming-your-kitten.png");
    height:200px; width:200px;
  
}

#image1:hover{
	content:url("http://animalrescuetracy.org/wp-content/uploads/2014/07/playful-kitten-6683.jpg");
}
&#13;
 <img  id="image1" src=""/>
&#13;
&#13;
&#13;