9.事件.html 1.7 KB

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