JS练习_鼠标事件

预览:

源码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鼠标事件</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>
<body>
<div class="box"></div>
<script>
    let box = document.querySelector(".box");
    box.onclick = function (){
        console.log("被点击");
    }
    box.onmouseenter = function (){
        console.log("鼠标移入")
    }
    box.onmousemove = function (){
        console.log("鼠标移出")
    }
</script>
</body>
</html>
posted @ 2021-09-22 11:59  博客zhu虎康  阅读(46)  评论(0编辑  收藏  举报