|
|
@@ -0,0 +1,38 @@
|
|
|
+<!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: #f00;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="box">
|
|
|
+ <div id="box1"></div>
|
|
|
+ </div>
|
|
|
+ <script>
|
|
|
+ // 事件冒泡
|
|
|
+ // 事件:冒泡 目标 捕获
|
|
|
+ let box = document.getElementById("box");
|
|
|
+ let box1 = document.getElementById("box1");
|
|
|
+ // box.onClick
|
|
|
+ box.addEventListener("click",function() {
|
|
|
+ console.log("1")
|
|
|
+ },true)
|
|
|
+ box1.addEventListener("click",function() {
|
|
|
+ console.log("2")
|
|
|
+ },true)
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|