jQuery基础:mouseeter( ) 与 mouseover( ) 区别

1、结论

  • mouseove:不论鼠标指针穿过被选元素或其子元素,都会触发;
  • mouseenter:只有在鼠标指针穿过被选元素时,才会触发事件;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{
             200px;
            height: 200px;
            padding: 5px;
            border: 1px red solid;
        }

        span{
            display: inline-block;
             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>
原文地址:https://www.cnblogs.com/gao-xiong/p/5935284.html