1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5 <title>鼠标经过时换一张图片</title> 6 <meta name="keywords" content="关键字列表" /> 7 <meta name="description" content="网页描述" /> 8 <link rel="stylesheet" type="text/css" href="" /> 9 <style type="text/css"> 10 </style> 11 </head> 12 <body> 13 <form> 14 <input type="button" onclick="myfunction()" value="调用函数"> 15 </form> 16 17 18 <img src='jd1.png' id='changeImage'> 19 <script type="text/javascript"> 20 //定义一个变量ig,把对象‘document’的值赋值给它,通过‘getElementById’方法获取‘changeImage’属性值 21 var ig = document.getElementById('changeImage'); 22 //给ig变量添加一个onmouseover事件,当鼠标移到上面就会变换一张图片 23 ig.onmouseover = function(){ 24 //当鼠标移上时,ig变量的src属性值改为'jd2.png' 25 ig.src='jd2.png' 26 } 27 ig.onmouseout = function(){ 28 ig.src='jd1.png' 29 } 30 function myfunction() 31 { 32 alert("调用函数以输出该提示窗口") 33 } 34 </script> 35 </body> 36 </html>
转载于:https://www.cnblogs.com/781206878-qq/p/6086622.html