对比onmouseover和onmouseenter
onmouseover和onmouseenter都属于事件类型,都是用来代表鼠标移入的,但是两者有什么区别呢?今天就更大家分享一下。
鼠标移上,对比onmouseover和onmouseenter,两者作用相同,但是onmouseenter效率更高。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn">点我</button>
<script type="text/javascript">
var a = document.getElementById('btn');
/*鼠标移上,对比onmouseover和onmouseenter,两者作用相同,但是onmouseenter效率更高*/
/*mouseover鼠标移入与 mouseout鼠标移出 对应*/
a.onmouseover=function(){
alert(4);
console.log('我是over我用了时长')
}
/*mouseenter鼠标移入 与mouseleave鼠标移出 对应*/
a.onmouseenter=function(){
alert(2);
console.log('我是enter我用了时长')
}
</script>
</body>
</html>
点击之后,浏览器中conlose中的显示结果。