|
@@ -0,0 +1,74 @@
|
|
|
|
+<!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: 400px;
|
|
|
|
+ height: 400px;
|
|
|
|
+ background-color:red;
|
|
|
|
+ }
|
|
|
|
+ .box2{
|
|
|
|
+ width: 200px;
|
|
|
|
+ height: 200px;
|
|
|
|
+ background-color:blue;
|
|
|
|
+ }
|
|
|
|
+ .box3{
|
|
|
|
+ width: 100px;
|
|
|
|
+ height: 100px;
|
|
|
|
+ background-color: yellow;
|
|
|
|
+ }
|
|
|
|
+ </style>
|
|
|
|
+</head>
|
|
|
|
+<body>
|
|
|
|
+ <div class="box1">
|
|
|
|
+ <div class="box2">
|
|
|
|
+ <div class="box3"></div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <script>
|
|
|
|
+ var oBxo1 = document.getElementsByClassName("box1")[0];
|
|
|
|
+ var oBxo2 = document.getElementsByClassName("box2")[0];
|
|
|
|
+ var oBox3 = document.getElementsByClassName("box3")[0];
|
|
|
|
+
|
|
|
|
+ // 事件机制 冒泡
|
|
|
|
+ // oBxo1.onclick = function(){
|
|
|
|
+ // console.log("box1");
|
|
|
|
+ // }
|
|
|
|
+ // oBxo2.onclick = function(){
|
|
|
|
+ // console.log("box2");
|
|
|
|
+ // }
|
|
|
|
+ // oBox3.onclick = function(){
|
|
|
|
+ // console.log("box3");
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // js事件机制分为 事件捕获 事件冒泡
|
|
|
|
+ // 事件捕获由外向内逐层触发 addEventListener 第三个参数为true
|
|
|
|
+ // 事件冒泡由内向外逐层触发 addEventListener 第三个参数为false
|
|
|
|
+
|
|
|
|
+ // js事件机制的顺序
|
|
|
|
+ oBxo1.addEventListener("click",function(){
|
|
|
|
+ console.log("box1");
|
|
|
|
+ },false)
|
|
|
|
+ oBxo2.addEventListener("click",function(){
|
|
|
|
+ console.log("box2");
|
|
|
|
+ },false)
|
|
|
|
+ oBox3.addEventListener("click",function(){
|
|
|
|
+ console.log("box3");
|
|
|
|
+ },false)
|
|
|
|
+
|
|
|
|
+ oBxo1.addEventListener("click",function(){
|
|
|
|
+ console.log("box1");
|
|
|
|
+ },true)
|
|
|
|
+ oBxo2.addEventListener("click",function(){
|
|
|
|
+ console.log("box2");
|
|
|
|
+ },true)
|
|
|
|
+ oBox3.addEventListener("click",function(){
|
|
|
|
+ console.log("box3");
|
|
|
|
+ },true)
|
|
|
|
+ </script>
|
|
|
|
+</body>
|
|
|
|
+</html>
|