7.事件.html 1.8 KB

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