16_事件流.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. #div1{
  14. width: 200px;
  15. height: 200px;
  16. background: gray;
  17. }
  18. #div2{
  19. width: 100px;
  20. height: 100px;
  21. background: aqua;
  22. }
  23. #div3{
  24. width: 50px;
  25. height: 50px;
  26. background: red;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="div1">
  32. <div id="div2">
  33. <div id="div3"></div>
  34. </div>
  35. </div>
  36. <script>
  37. var div1 = document.getElementById('div1')
  38. var div2 = document.getElementById('div2')
  39. var div3 = document.getElementById('div3')
  40. div1.addEventListener('click',function(){
  41. console.log(111)
  42. },true)
  43. div2.addEventListener('click',function(){
  44. console.log(222)
  45. },true)
  46. div3.onclick = function(){
  47. console.log(333)
  48. }
  49. </script>
  50. </body>
  51. </html>