Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
大多数时候,我看到代码为链接或 div 或按钮注册事件侦听器,并从那里处理所有事情。但是事件捕获和冒泡可以很好地处理后代级别的事件,然后是祖先级别的事件。但是,我们希望在 2 个不同的地方聆听的好例子是什么?
我在一本书中看到一个例子:
如果你正在设计一个“打地鼠”游戏,你想听地鼠 div 的事件来知道“命中”和父 div 中的空白,从而知道“未命中”。