1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- *{
- margin: 0;
- padding: 0;
- }
- #div1{
- width: 300px;
- height: 300px;
- background: greenyellow;
- }
- #div2{
- width: 200px;
- height: 200px;
- background: red;
- }
- #div3{
- width: 100px;
- height: 100px;
- background: orange;
- }
- </style>
- </head>
- <body>
- <div id="div1">
- <div id="div2">
- <div id="div3"></div>
- </div>
- </div>
- <script>
- /*
- js的事件流 从触发事件到处理事件的整个流程
- 包括事件捕获和事件冒泡
- */
- var div1 = document.getElementById('div1')
- var div2 = document.getElementById('div2')
- var div3 = document.getElementById('div3')
- div1.addEventListener('click',function(){
- console.log(111)
- },true)
- div2.addEventListener('click',function(){
- console.log(222)
- },true)
- // div3.addEventListener('click',function(){
- // console.log(333)
- // },true)
- div3.onclick = function(){
- console.log(333)
- }
- </script>
- </body>
- </html>
|