1、结论
- mouseove:不论鼠标指针穿过被选元素或其子元素,都会触发;
- mouseenter:只有在鼠标指针穿过被选元素时,才会触发事件;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ width: 200px; height: 200px; padding: 5px; border: 1px red solid; } span{ display: inline-block; width: 50px; height: 50px; background: blue; } </style> </head> <body> <div class="over"> <span>0</span> </div> <div class="enter"> <span>0</span> </div> </body> <script src="libs/jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(function(){ var x = 0; var y = 0; $(".over").mouseover(function(){ $(this).find("span").text(x+=1); }); $(".enter").mouseenter(function(){ $(this).find("span").text(x+=1); }) }) </script> </html>
时间: 2024-10-27 13:43:58