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>
相关推荐
HDO清风3 分钟前
CASIA-HWDB2.x 数据集DGRL文件解析(python)
开发语言·人工智能·pytorch·python·目标检测·计算机视觉·restful
2201_756989093 分钟前
C++中的事件驱动编程
开发语言·c++·算法
会飞的战斗鸡9 分钟前
JS中的链表(含leetcode例题)
javascript·leetcode·链表
多米Domi01114 分钟前
0x3f 第48天 面向实习的八股背诵第五天 + 堆一题 背了JUC的题,java.util.Concurrency
开发语言·数据结构·python·算法·leetcode·面试
2301_8223776515 分钟前
模板元编程调试方法
开发语言·c++·算法
csbysj202018 分钟前
Python 循环嵌套
开发语言
测试_AI_一辰21 分钟前
Agent & RAG 测试工程05:把 RAG 的检索过程跑清楚:chunk 是什么、怎么来的、怎么被命中的
开发语言·人工智能·功能测试·自动化·ai编程
Coding茶水间23 分钟前
基于深度学习的输电电力设备检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
开发语言·人工智能·深度学习·yolo·目标检测·机器学习
清风~徐~来27 分钟前
【视频点播系统】BRpc 介绍及使用
开发语言
啟明起鸣29 分钟前
【C++ 性能提升技巧】C++ 的引用、值类型、构造函数、移动语义与 noexcept 特性,可扩容的容器
开发语言·c++