9.事件.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. <style>
  8. #box {
  9. width: 300px;
  10. height: 300px;
  11. background: #ff0;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="box"></div>
  17. <input type="text">
  18. <script>
  19. var box = document.getElementById("box");
  20. var inp = document.querySelector("input");
  21. // 1.点击事件
  22. // box.onclick = function() {
  23. // console.log("点击");
  24. // }
  25. // 2.双击
  26. // box.ondblclick = function() {
  27. // console.log("双击")
  28. // }
  29. // 3.鼠标滑动
  30. // box.onmousemove = function(){
  31. // console.log("鼠标滑动")
  32. // }
  33. // 4.鼠标划出
  34. // box.onmouseout = function(){
  35. // console.log("鼠标划出")
  36. // }
  37. // 5.鼠标划入
  38. // box.onmouseover = function() {
  39. // console.log("鼠标划入")
  40. // }
  41. // 6.鼠标按下
  42. box.onmousedown = function() {
  43. console.log("鼠标按下")
  44. }
  45. // 7.鼠标抬起
  46. box.onmouseup = function(){
  47. console.log("鼠标抬起")
  48. }
  49. // 8.键盘按下
  50. inp.onkeydown = function(eve) {
  51. console.log("键盘按下",eve)
  52. if(eve.keyCode == 9) {
  53. console.log("按下tab")
  54. }
  55. }
  56. // 9.键盘抬起
  57. // inp.onkeyup = function() {
  58. // console.log("键盘抬起")
  59. // }
  60. // 10.键盘按下 回车键
  61. // inp.onkeypress = function() {
  62. // console.log("键盘按下")
  63. // }
  64. </script>
  65. </body>
  66. </html>