12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <!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>
- #div1 {
- width: 300px;
- height: 300px;
- background: red;
- }
- #div2 {
- width: 200px;
- height: 200px;
- background: green;
- }
- #div3 {
- width: 100px;
- height: 100px;
- background: pink;
- }
- </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('div1')
- },true)
- div2.addEventListener('click',function(){
- console.log('div2')
- },true)
- // div3.addEventListener('click',function(){
- // console.log('div3')
- // },true)
- div3.onclick = function(){
- console.log('div3')
- }
- </script>
- </body>
- </html>
|