| 123456789101112131415161718192021222324252627282930313233343536 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #box{
- width: 200px;
- height: 200px;
- background-color: red;
- }
- </style>
- </head>
- <body>
- <div id="box"></div>
- <button id="btn">点击我</button>
- <script>
- // 获取元素
- var box = document.querySelector("#box");
- var btn = document.querySelector("#btn");
- // 鼠标按下事件
- btn.onmousedown = function(){
- console.log("鼠标按下");
- }
- // 鼠标松开事件
- btn.onmouseup = function(){
- console.log("鼠标松开");
- }
- // 鼠标移动事件
- box.onmousemove = function(){
- console.log("鼠标移动");
- }
- </script>
- </body>
- </html>
|