了解路由事件:为什么同时需要冒泡事件和隧道事件? [英] Understanding Routing Events: Why I need both, bubble and tunnel events?

查看:203
本文介绍了了解路由事件:为什么同时需要冒泡事件和隧道事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关路由事件的这篇好文章,我了解为什么有时需要泡泡事件,有时又需要隧道事件.

I read this good article about Routed Events, and I understood why we need sometimes bubble Events and sometime we need tunnel Events.

我不了解的是,当我们使用隧道事件时,为什么在处理或到达源元素之后仍然启动气泡事件?

What I didn't understand is, when we use the tunnel Event, why after it is handled or reached to the source element, still the bubble event is launched?

提前谢谢!

推荐答案

文章说,如果将图像放置在按钮上,然后单击该图像,则将触发该图像的隧道事件.但是您很有可能还希望像单击按钮本身一样处理该单击,因此还会触发一个冒泡事件,该事件会冒泡直到发生按钮本身上的click事件(因为该按钮拥有图像),因此您可以使用按钮的常规事件处理程序将图像单击视为按钮单击.

The article says that if you put an image on a button, and that image is clicked, the tunnel event for that image will fire. But it is highly likely that you would also want to handle that click as if the button itself was clicked, so a bubble event is also fired which bubbles up to the click event on the button itself (because the button owns the image), so that you can treat the image click like a button click, using the usual event handler for the button.

这篇关于了解路由事件:为什么同时需要冒泡事件和隧道事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆