The different of mouseover and mouseenter

l论事件onmouseover 和 onmouseenter;同类比较onmouseout 和 onmouseleave;

使用onmouseover时,鼠标除了被设置事件的元素,还会触发其子元素; 而onmouseenter只会触发被设置了事件的元素,子元素不受影响。

支持度:mouseenter,mouseleavei  IE8+的浏览器支持,safari 5不支持

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>mouseover 和 mouseenter的区别</title>
<style>
body{
padding: 0;
margin: 0; }
#box1,
#box2{
width: 300px;
height: 100px;
margin-top: 100px;
padding-top: 50px;
background: #f00; }
#box1 p,
#box2 p{
width: 70%;
height: 50px;
line-height: 50px;
text-align: center;
background: #ccc; }
</style>
<script>
window.onload = function(){
var box1 = document.getElementById("box1");
var box2 = document.getElementById("box2");
var num1 = document.getElementById("num1");
var num2 = document.getElementById("num2");
box1.onmouseover = function(){
num1.innerHTML++;
}
box2.onmouseenter = function(){
num2.innerHTML++;
}
}
</script>
</head>
<body>
<div id="box1">
<p>事件mouseover: <span id="num1">1</span></p>
</div>
<div id="box2">
<p>事件mouseenter: <span id="num2">1</span></p>
</div> </body>
</html>
上一篇:LDA 初见(JGibbLDA-v.1.0 eclipse使用)


下一篇:【Java基础】基本语法-变量与运算符