| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #box {
- width: 400px;
- height: 400px;
- background: #00f;
- }
- #box1 {
- width: 200px;
- height: 200px;
- background: #0ff;
- }
- </style>
- </head>
- <body>
- <!--
- 事件捕获
- 目标阶段
- 事件冒泡
- -->
- <div id="box">
- <div id="box1"></div>
- </div>
- <script>
- var box = document.getElementById("box");
- var box1 = document.getElementById("box1");
- // box.onclick = function (event) {
- // console.log("box")
- // }
- // box1.onclick = function (event) {
- // // event.stopPropagation();
- // event.cancelBubble = true;
- // console.log("box1");
- // }
- // 监听事件
- // box.addEventListener('click',function() {
- // console.log("box")
- // },false)
- // box1.addEventListener('click',function(event) {
- // // event.stopPropagation();
- // console.log("box1")
- // },false)
- // box.removeEventListener("xxx")
- </script>
- </body>
- </html>
|