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>
相关推荐
奔跑的卡卡3 分钟前
线上Web异常发现为什么总是滞后?一套自研Web实时异常分析监控系统整体架构拆解
前端·web安全·架构
秋田君4 分钟前
Qt_Qt(c++)开发中常见错误与解决方法
开发语言·c++·qt
夏霞22 分钟前
c# 不支持的目标框架 解决方案
开发语言·c#
梦曦i23 分钟前
create-uni-app v1.1.0:结构化生成,工程骨架更规范
前端·uni-app
流光D26 分钟前
AI时代,搭建 web 站点并配置 nginx 反向代理流程
运维·服务器·前端·人工智能·nginx·ai·ai编程
雄哥00730 分钟前
java代码反编译CFR
java·开发语言·反编译·cfr
PBitW31 分钟前
Travel Planner — 智能旅行行程规划助手
前端·后端
lsylalalala34 分钟前
多线程(2)
java·开发语言·多线程
梨想橙汁38 分钟前
CSS Grid 网格布局:二维布局神器,轻松实现复杂网页排版
前端·css
lhldsg38 分钟前
酒吧点餐小程序开发:从需求分析到技术落地实战
java·前端·小程序·架构·交友