js 鼠标事件

时间:2021-05-13 15:28:04
<html><head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<img name="icon" src="img/img_01.jpg"> <script>
var img = document.getElementsByName('icon')[];
// 移进图片
img.onmouseover = function(){
console.log('鼠标进入图片区域');
}
// 在图片中移动
img.onmousemove = function(){
console.log('鼠标在图片上移动');
}
// 离开图片
img.onmouseout = function(){
console.log('鼠标已出图片')
} </script> </body></html>