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>
相关推荐
threerocks20 小时前
我把「双语刷 X + 深度 AI 改写 + 去 AI 味过朱雀」做进了浏览器和终端:X Polyglot 正式上架 Chrome 商店
chrome
两点王爷1 天前
Java 面试高频:JWT、Cookie、Session、Token 鉴权详解
java·开发语言·面试
Java展博1 天前
[前端够用就好] 跨域报错时,浏览器到底在拦谁
前端·状态模式
用户112936112191 天前
npm 都提示成功了,node_modules 为什么还占着 370M?
linux·前端·后端
微笑星河q1 天前
C++高阶之【多态】
开发语言·c++
掘金安东尼1 天前
Agent Harness 也有 benchmark:评分榜与评测工作台现状
前端·agent
digger_4191 天前
从零理解 Electron:主进程、渲染进程、preload 与 IPC 实战
前端·electron
去伪存真1 天前
别让你的 RAG 平台“花五份钱、答一份结巴的题”:幂等性架构的自我修养
前端·agent
小宋10211 天前
Chrome 的 AI 功能在后台偷跑流量:把端侧模型做成可版本化的分发制品,用下载资格门控、差分更新与「下载未使用率」验收
大数据·人工智能·chrome