在“链接”和“链接”处监听事件的一个好例子是什么? (或 div)以及父元素或祖先元素?

发布于 2024-09-06 14:06:30 字数 106 浏览 2 评论 0 原文

大多数时候,我看到代码为链接、div 或按钮注册事件侦听器,并从那里处理所有内容。但是事件捕获和冒泡对于处理后代级别的事件以及祖先级别的事件很有帮助。但是我们想要在两个不同的地方聆听的好例子是什么?

Most of the time I see code registering an event listener for a link or a div or button, and handle everything from there. But the event capturing and bubbling is good to handle events at the offspring and then at the ancestor level. But what is a good example we will want to listen at 2 different places?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断肠人 2024-09-13 14:06:30

我在一本书上看到一个例子:

如果你正在设计一个“打地鼠”的游戏,你想监听地鼠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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文