10_DOM事件对象.html 699 B

1234567891011121314151617181920212223
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 获取整个文档
  11. var doc = document.documentElement;
  12. // 事件对象 事件默认就有的一个参数
  13. doc.onclick = function(e){
  14. // 事件对象中包含很多事件相关的属性和方法
  15. console.log(e);
  16. // 事件对象中的clientX(横向位置)和clientY(纵向位置)属性 表示鼠标点击的位置
  17. console.log(e.clientX);
  18. console.log(e.clientY);
  19. }
  20. </script>
  21. </body>
  22. </html>