19.事件流.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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: 400px;
  10. height: 400px;
  11. background: #00f;
  12. }
  13. #box1 {
  14. width: 200px;
  15. height: 200px;
  16. background: #0ff;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <!--
  22. 事件捕获
  23. 目标阶段
  24. 事件冒泡
  25. -->
  26. <div id="box">
  27. <div id="box1"></div>
  28. </div>
  29. <script>
  30. var box = document.getElementById("box");
  31. var box1 = document.getElementById("box1");
  32. // box.onclick = function (event) {
  33. // console.log("box")
  34. // }
  35. // box1.onclick = function (event) {
  36. // // event.stopPropagation();
  37. // event.cancelBubble = true;
  38. // console.log("box1");
  39. // }
  40. // 监听事件
  41. // box.addEventListener('click',function() {
  42. // console.log("box")
  43. // },false)
  44. // box1.addEventListener('click',function(event) {
  45. // // event.stopPropagation();
  46. // console.log("box1")
  47. // },false)
  48. // box.removeEventListener("xxx")
  49. </script>
  50. </body>
  51. </html>