mouseenter:只有移入当前元素才会触发,对应mouseleave
hover使用的是mouseenter与mouseleave
mouseover:在移入子元素时也会触发,对应mouseout
<div id="div1">div1
<div id="div2">div2</div>
</div>
<div id="div3">div3
<div id="div4">div4</div>
</div>
#div1,#div3 {
width: 200px;
height: 200px;
background: #bfa;
position: absolute;
}
#div3{
left: 250px;
}
#div2,#div4 {
width: 100px;
height: 100px;
background: skyblue;
position: relative;
top: 50px;
left: 50px;
}
在进入子元素的时候 也会使得出现进入 离开的触发
$('#div1').mouseover(function(){
console.log('mouseover进入')
}).mouseout(function(){
console.log('mouseout离开')
})
$('#div3').mouseenter(function(){
console.log('mouseenter进入')
}).mouseleave(function(){
console.log('mouseleave离开')
})
//可以加多个
document.getElementById('div1').addEventListener('click',function(){
console.log('click1');
})
document.getElementById('div1').addEventListener('click',function(){
console.log('click2');
})
//不可以两次 document.getElementById('div1').onclick=function(){ console.log('click1'); } //只有一个生效 document.getElementById('div1').onclick=function(){ console.log('click2'); }