---
title: "触发 mouseover 事件和 mouseenter 事件 的区别"
author: "jackroomage"
date: "2013-06-17T15:02:01Z"
tags: []
categories: ["Web前端"]
slug: "mouseover-mouseenter"
draft: false
lastmod: "2013-06-17T15:02:01Z"
id: 1888207
url: "https://jackroomage.iteye.com/blog/1888207"
---

来源：

[http://www.w3school.com.cn/tiy/t.asp?f=jquery\_event\_mouseenter\_mouseover](http://www.w3school.com.cn/tiy/t.asp?f=jquery_event_mouseenter_mouseover)

 

&lt;html&gt;  
&lt;head&gt;  
&lt;script type="text/javascript" src="/jquery/jquery.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript"&gt;  
x=0;  
y=0;  
$(document).ready(function(){  
  $("div.over").mouseover(function(){  
    $(".over span").text(x+=1);  
  });  
  $("div.enter").mouseenter(function(){  
    $(".enter span").text(y+=1);  
  });  
});  
&lt;/script&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;p&gt;不论鼠标指针穿过被选元素或其子元素，都会触发 mouseover 事件。&lt;/p&gt;  
&lt;p&gt;只有在鼠标指针穿过被选元素时，才会触发 mouseenter 事件。&lt;/p&gt;  
&lt;div class="over" style="background-color:lightgray;padding:20px;width:40%;float:left"&gt;  
&lt;h2 style="background-color:white;"&gt;被触发的 Mouseover 事件：&lt;span&gt;&lt;/span&gt;&lt;/h2&gt;  
&lt;/div&gt;  
&lt;div class="enter" style="background-color:lightgray;padding:20px;width:40%;float:right"&gt;  
&lt;h2 style="background-color:white;"&gt;被触发的 Mouseenter 事件：&lt;span&gt;&lt;/span&gt;&lt;/h2&gt;  
&lt;/div&gt;  
&lt;/body&gt;  
&lt;/html&gt;