JavaScript鼠标点击事件

鼠标事件指通过鼠标触发事件, 类似用户的行为:

Onclick:当单击鼠标时运行脚本

Ondblclick:当双击鼠标时运行脚本

Onmousedown:当按下鼠标按钮时运行脚本

onmousemove:当鼠标指针移动时运行脚本         

Onmouseout:当鼠标指针移出元素时运行脚本     

Onmouseover:当鼠标指针移至元素之上时运行脚本

Onmouseup:当松开鼠标按钮时运行脚本         

Onmousewhee;当转动鼠标滚轮时运行脚本         

Onscroll:当滚动元素的滚动条时运行脚本

<!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>鼠标事件</title>

    <style>

        div{

            width: 200px;

            height: 200px;

            background-color: blue;

        }

    </style>

</head>

<body>

    <div id="box"></div>

    <script>

       var box = document.getElementById("box");

       //鼠标单击事件

    //    box.onclick = function(){

    //        alert(123);

    //    }

       

    //鼠标双击事件  

    // box.ondblclick = function(){

    //         alert(123);

    // }

    //鼠标移至元素之上 事件

        // box.onmouseover = function(){

        //     console.log("鼠标在元素上面")

        // }

    //鼠标移出元素 事件

        // box.onmouseout = function(){

        //         alert(456);

        // }

    //鼠标移动时元素事件

        // box.onmousemove = function(){

        //     console.log("鼠标在移动") ;

        // }

        // box.onmousedown = function(){

        //     console.log("当前鼠标为按下状态")

        // }

        // box.onmouseup = function(){

        //     console.log("当前鼠标为松开状态")

        // }

        // box.onmousewheel = function(){

        //     console.log("当前为滚轮状态")

        // }

        // window.onscroll = function(){

        //     alert("滚动条事件");

        // }

    </script>

</body>

</html>

  • 1
    点赞
  • 10
    收藏 更改收藏夹
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值