jQuery细节总结

1、mouseover和mouseenter 区别

  mouseenter指鼠标进入元素时触发,鼠标在元素子元素上不触发。

  mouseover指鼠标进入元素时触发,在元素进入子元素会触发。

在此引用一个例子

 1 <body>
 2 
 3 <p>不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件。</p>
 4 <p>只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件。</p>
 5 <div class="over" style="background-color:lightgray;padding:20px;40%;float:left">
 6     <h2 style="background-color:white;">被触发的 Mouseover 事件:<span></span></h2>
 7 </div>
 8 <div class="enter" style="background-color:lightgray;padding:20px;40%;float:right">
 9     <h2 style="background-color:white;">被触发的 Mouseenter 事件:<span></span></h2>
10 </div>
11 <script type="text/javascript">
12     x=0;
13     y=0;
14     $(document).ready(function(){
15         $("div.over").mouseover(function(){
16             $(".over span").text(x+=1);
17         });
18         $("div.enter").mouseenter(function(){
19             $(".enter span").text(y+=1);
20         });
21     });
22 </script>
23 </body>

  

原文地址:https://www.cnblogs.com/yanaweb/p/4981300.html