JQuery mouseover、mouseenter区别

本文通过HTML、CSS和JavaScript代码实例,详细解释了HTML元素上的mouseover和mouseenter事件的区别,包括它们如何响应鼠标操作,以及在父元素与子元素上的行为差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
<!--    mouseover、mouseenter的区别:div里套div。见备注。和事件冒泡有关系。
    不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件
    只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件(穿过子元素不会触发)-->

    <style type="text/css">
        div{margin:auto;}
        #parent{width:300px;height:300px;margin-top:100px;background-color:Red;}
        #child{width:100px;height:100px;background-color:gold;position:relative;top:100px;}
    </style>
    <script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#parent").mouseenter(function () {
                alert('parent div enter');
            });


            $("#parent").mouseover(function () {
                alert('parent div over');
            });


            $("#child").mouseenter(function () {
                alert('child div enter');
            });


            $("#child").mouseover(function () {
                alert('child div over');
            });
        });
    </script>
</head>
<body>
    <div id="parent">
        <div id="child">
        </div>
    </div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值