10_鼠标移入事件.html 750 B

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. #box{
  9. width: 200px;
  10. height: 200px;
  11. background-color: blue;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="box"></div>
  17. <script>
  18. // 获取元素
  19. var box = document.getElementById("box");
  20. // 绑定事件
  21. // 鼠标移入事件 mouseover
  22. // 鼠标移出事件 mouseout
  23. box.onmouseover = function(){
  24. console.log("鼠标移入了");
  25. }
  26. box.onmouseout = function(){
  27. console.log("鼠标移出了");
  28. }
  29. </script>
  30. </body>
  31. </html>