12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <!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>
- #box1 {
- width: 500px;
- height: 500px;
- background: red;
- }
- #box2 {
- width: 300px;
- height: 300px;
- background: yellowgreen;
- }
- </style>
- </head>
- <body>
- <div id="box1">
- <div id="box2"></div>
- </div>
- <script>
- var box1 = document.getElementById("box1");
- // box1.onclick
- /**
- * 事件:
- * 捕获:true
- * 目标
- * 冒泡:false
- */
- /**
- * 事件流:
- * xxx.addEventListener("监听方法",执行函数,true/false);
- */
- box1.addEventListener("click",function(){
- console.log("111")
- },true)
- box2.addEventListener("click",function(){
- console.log("222")
- // event.stopPropagation()
- },true)
- </script>
- </body>
- </html>
|