1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <style> .box { width: 500px; height: 500px; background-color: #000; } .r { width: 400px; height: 400px; background-color: red; } .g { width: 300px; height: 300px; background-color: green; } .b { width: 200px; height: 200px; background-color: blue; } </style> <div class="box"> <div class="r"> <div class="g"> <div class="b"></div> </div> </div> </div> <script> const qs = (e) => document.querySelector(e) const box = qs('.box') const r = qs('.r') const g = qs('.g') const b = qs('.b')
const op = { capture: false, once: false, passive: false, } function bindClick(e) { const _this = e e.addEventListener( 'click', function (event) { console.log(_this.getAttribute('class')) }, op ) }
bindClick(box) bindClick(r) bindClick(g) bindClick(b)
</script>
|