7_事件.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #div1{
  10. width: 200px;
  11. height: 200px;
  12. background: red;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="div1">
  18. <input type="text" id="input1">
  19. </div>
  20. <script>
  21. var div1 = document.getElementById('div1')
  22. var input1 = document.getElementById('input1')
  23. //点击事件
  24. // div1.onclick = function(){
  25. // console.log(111111)
  26. // }
  27. //双击事件
  28. // div1.ondblclick = function(){
  29. // console.log(2222)
  30. // }
  31. //鼠标移动
  32. // div1.onmousemove = function(){
  33. // console.log(333)
  34. // }
  35. //鼠标划出
  36. // div1.onmouseout = function(){
  37. // console.log(444)
  38. // }
  39. //按下鼠标触发事件
  40. // div1.onmousedown = function(e){
  41. // console.log(555)
  42. // //鼠标相对于浏览器视口的坐标轴
  43. // // console.log(e.clientX,e.clientY)
  44. // }
  45. //松开鼠标触发事件
  46. // div1.onmouseup = function(){
  47. // console.log(111)
  48. // }
  49. // input1.onkeydown = function(e){
  50. // console.log(e.keyCode)
  51. // if(e.keyCode == 13){
  52. // console.log('我是回车')
  53. // }
  54. // }
  55. // input1.onkeyup = function(){
  56. // console.log('onkeyup')
  57. // }
  58. input1.onkeypress = function(){
  59. console.log('onkeypress')
  60. }
  61. </script>
  62. </body>
  63. </html>