jQuery基础:mouseeter( ) 与 mouseover( ) 区别
1、结论
- mouseove:不论鼠标指针穿过被选元素或其子元素,都会触发;
- mouseenter:只有在鼠标指针穿过被选元素时,才会触发事件;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
padding: 5px;
border: 1px red solid;
}
span{
display: inline-block;
width: 50px;
height: 50px;
background: blue;
}
</style>
</head>
<body>
<div class="over">
<span>0</span>
</div>
<div class="enter">
<span>0</span>
</div>
</body>
<script src="libs/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
var x = 0;
var y = 0;
$(".over").mouseover(function(){
$(this).find("span").text(x+=1);
});
$(".enter").mouseenter(function(){
$(this).find("span").text(x+=1);
})
})
</script>
</html>
keep learning
浙公网安备 33010602011771号