<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <button id="btn1">单击</button> <button id="btn2">双击</button> </body> <script> var btn1 = document.getElementById('btn1'); var btn2 = document.getElementById('btn2'); btn1.onclick=function(){ alert('单击事件') } btn2.ondblclick=function(){ alert('双击事件') } </script> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <button id="btn">点妓</button> </body> <script> var btn = document.getElementById('btn'); //鼠标按下事件 btn.onmousedown = function(){ console.log('按下了鼠标'); } //鼠标弹起事件 btn.onmouseup = function(){ console.log('鼠标弹起事件'); } //鼠标单击事件 btn.onclick=function(){ console.log('点妓了一次'); } //鼠标移动事件 document.onmousemove=function(){ //解决兼容性问题 var e = e ||event; document.title="X:"+e.clientX+"Y:"+e.clientY; } </script> </html>
点击 "运行实例" 按钮查看在线实例