請教下mouseover()和mouseenter()之間的區別
代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo009基礎事件</title>
<script type="text/javascript" src="jquery-1.12.4.min.js"></script>
<style type="text/css">
#box1{
width: 200px;
height: 200px;
border:1px solid black;
}
#box2{
width: 100px;
height: 100px;
border:1px solid black;
position: absolute;
top: 300px;
}
</style>
</head>
<body>
<div id="box1">
<div id="box2"></div>
</div>
<script type="text/javascript">
? ? ? ? /*$('#box1').mouseover(function(){
? ? ? ? ?$('#box1').css('background','red');
? ? ? ? });*/
? ? ? ? $('#box1').mouseenter(function(){
? ? ? ? ?$('#box1').css('background','red');
? ? ? ? });
</script>
</body>
</html>
當把子元素box2定位到父元素外面的話,子元素鼠標移入使用monseenter()方法也會產生事件冒泡。但是不進行定位的話就不會產生冒泡。請問為什么?
2016-06-27
mouseover是鼠標在元素上面就會觸發,mouseenter是鼠標穿過元素才會觸發