HTML中图片ON mouse事件怎样使用,例如已经有图片1,我想要鼠标移到图片1时自动替换成图片2,请代码

如题所述

<img src=图片1.jpg onmouseover="javascript:this.src='图片2.jpg'" onmouseout="javascript:this.src='图片1.jpg'" />
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-25
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />

</head>

<body>

<img src="2000.gif" width="200" height="200" onMouseover="javascript:this.src='2.jpg'"/>

</body>
</html>
你把图片地址换一下。换成你本地的图片就可以看到效果了
第2个回答  推荐于2018-03-15
这段代码就是实现鼠标移动到另外一个图片的时候更改图片,需要使用javascript
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>

<body>
<a href="http://www.w3school.com.cn"
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>本回答被提问者和网友采纳
第3个回答  2018-03-14
<img src="图片1.jpg" name="p" onmouseover="p.src='图片2.jpg'" onmouseout="p.src='图片1.jpg'">