js鼠标经过切换图片

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>js鼠标经过切换图片</title>
 6     <script>
 7         window.onload = function () {
 8             //获取图片
 9             var img = document.getElementById("img");
10 
11             //鼠标经过图片
12             img.onmouseover = function () {
13                 this.src = "image/8.jpg"
14             }
15 
16             //鼠标离开图片
17             img.onmouseout = function () {
18                 this.src = "image/9.jpg";
19             }
20         }
21     </script>
22 </head>
23 <body>
24     <img id="img" src="image/9.jpg"/>
25 </body>
26 </html>

 

posted @ 2017-08-18 16:26  宋发元  阅读(957)  评论(0)    收藏  举报