在“链接”和“链接”处监听事件的一个好例子是什么? (或 div)以及父元素或祖先元素?
大多数时候,我看到代码为链接、div 或按钮注册事件侦听器,并从那里处理所有内容。但是事件捕获和冒泡对于处理后代级别的事件以及祖先级别的事件很有帮助。但是我们想要在两个不同的地方聆听的好例子是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在一本书上看到一个例子:
如果你正在设计一个“打地鼠”的游戏,你想监听地鼠div的事件来知道“击中”以及父div中的空白,从而认识一个“小姐”。
I saw an example in a book:
if you are designing a "whack a mole" game, you want to listen to the event of the mole div to know of a "hit" and the empty space in the parent div, so as to know a "miss".