DOM---鼠标事件类型(移入移出)

移入 移出mouseenter mouseleave

在父盒子上触发,在孩子盒子上不触发

移入 移出mouseover mouseout全触发

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 200px;
            height: 200px;
            background: yellow;
        }
        #child{
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
    <div id="box">鼠标移入移出
        <div id="child"></div>
    </div>
    <script>

        // 移入  移出mouseover    mouseout
        // 都触发
        box.onmouseover = function(){
            console.log("鼠标移入")
        }

        box.onmouseout = function(){
            console.log("鼠标移出")
        

        // 移入  移出mouseenter    mouseleave
        // 在父盒子上触发,在孩子盒子上不触发
        box.onmouseenter = function(){
            console.log("鼠标移入")
        }

        box.onmouseleave = function(){
            console.log("鼠标移出")
        }
    </script>
</body>
</html>
相关推荐
Dream_ksw3 小时前
Python 基础
开发语言·python
weixin_428005303 小时前
C#调用 AI学习从0开始-第2阶段(Function Calling+工具调用智能体)-第9天实战-实现计算器工具
开发语言·学习·c#·functioncalling·ai实现计算器工具
John_ToDebug4 小时前
在 Windows 上搭建 Chromium 148 内核编译环境:一份实战笔记
chrome·经验分享·笔记
lichenyang4534 小时前
鸿蒙 Stage 模型到底是什么?一篇讲清 Ability、EntryAbility 和入口文件为什么这么设计
前端
特种加菲猫4 小时前
C++11核心特性深度解析:从列表初始化到lambda与包装器
开发语言·c++
JSMSEMI114 小时前
JSM12N60C 600V N沟道增强型功率MOSFET
开发语言·javascript·ecmascript
设计师小聂!4 小时前
Java异常处理
java·开发语言·后端·编辑器·idea
ihuyigui4 小时前
国际商超零售短信接口
大数据·前端·后端·架构·零售
Yan-英杰4 小时前
从零玩转搜索引擎 API: 多引擎整合实战
服务器·前端·microsoft
清水白石0084 小时前
从打印对象到高质量调试:彻底理解 Python 中 `__repr__` 和 `__str__` 的区别
开发语言·python