关于js中定义图片对象的鼠标经过效果

我想实现一段特效,是图片在鼠标经过时变成另外一张图片,原来写的是这样子的:

求大侠帮助实现:怎样在这段代码中加入鼠标经过时变为另一张图片的效果。万分感谢!

你就不能把代码直接贴出来。。。还的我自己打一次

<html>
<head>
<meta charset="utf-8" />
<style>
img{
width:100px;
height:100px;
}
</style>

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script>
$(document).ready(function(){
var i = 0;
$("img").mouseover(function(){
i++;
$(this).attr("title",imgs[i%3].title);
$(this).attr("src",imgs[i%3].src);
});
});

var  imgs = [
{
title:'title1',
url:'#',
src:'1.png'
},{
title:'title2',
url:'#',
src:'2.png'
},{
title:'title3',
url:'#',
src:'3.png'
}
];

</script>
</head>

<body>
<img src="1.png" title="title1"/>
</body>
</html>

追问

呵呵,不好意思。我当时往上贴了几次都没粘上,就截了个图。你的这个我看懂了,但你没明白我的意思,可能也是我没有表述清楚,是1、2、3这三张图片都在鼠标经过的时候分别显示另一张图片,那要怎么写呢?

追答

line15开始

$("img").each(function(){
    $(this).mouseover(function(){
        var randam = Math.floor(Math.random()*10);        
        //0~9的随机数
        
        $(this).attr("title",imgs[randam%3].title);                             //不清楚你需要的新title和新src是                         
        //什么,还是沿用的之前的imgs对象
        $(this).attr("src",imgs[randam%3].src);
    });
});

 


全部都是jQuery语法

温馨提示:答案为网友推荐,仅供参考