简体   繁体   English

如何在捕获阶段触发自定义事件

[英]How to trigger a custom event in capture phase

Is there a way to trigger a custom event in javascript, so that it will propagate using the capture model? 有没有一种方法可以触发javascript中的自定义事件,以便它可以使用capture模型传播?

I have a hierarchy of elements that I use as a mean to communicate between objects. 我有一个元素层次结构,用作在对象之间进行通信的手段。 Each level of the hierarchy represents a sub-family of object. 层次结构的每个级别代表对象的一个​​子族。 Ideally, I could trigger an event to each family's or sub-family's objects using their common ancestor. 理想情况下,我可以使用其共同祖先触发每个家庭或子家庭的对象的事件。

eg: 例如:

animals |_ | mammals | |_cats | |_dogs |_ reptiles |_alligators |_dinosaurs

(please no comments on my inadequate taxonomy :) ) (请不要对我的分类法不足发表评论:))

I would like to be able to trigger an event for all animals, all mammals or all cats, or event to a single cat instance. 我希望能够触发所有动物,所有哺乳动物或所有猫的事件,或触发单个猫实例的事件。

However, I can only find examples of custom events using the bubbling phase, so I want to know if it's me missing something or is this really impossible. 但是,我只能在冒泡阶段找到自定义事件的示例,因此我想知道是我遗漏了某些东西还是这真的不可能。

I know I can use event delegation on the root element for all instance, but it will scale really badly (this system needs to handle thousands of events of all types). 我知道我可以在所有实例的根元素上使用事件委托,但是这样做的伸缩性很差(此系统需要处理数千个各种类型的事件)。

Any ideas? 有任何想法吗?

对于当前的DOM事件规范,这是不可能的,因为它仅支持冒泡阶段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 KnockoutJS:处理事件捕获阶段 - KnockoutJS: Handle event capture phase 如何在 React-js 中为捕获阶段注册事件处理程序? - how to register an event handler for the capture phase in React-js? 如何使用自定义事件(特别是自定义dataTransfer属性)触发事件? - How to trigger an event with a custom event (specifically a custom dataTransfer property)? e.stopPropogation()是否等效于Click事件的捕获阶段? - e.stopPropogation() Equivalent for Capture Phase of Click Event? stopPropgation 是否会阻止事件在捕获阶段传播? - Does stopPropgation stop the event from propagating in the capture phase? 我可以在同一元素上附加捕获和气泡阶段事件处理程序吗? - Can i attach capture and bubble phase event handler on the same element? stopPropagation() 是否从捕获阶段停止执行事件? - Does stopPropagation() stops executing the event from capture phase? 如何正确触发jQuery UI自定义事件? - How to trigger a jQuery UI custom event correctly? 如何创建自定义事件以在无服务器上触发 function - How create a custom event to trigger a function on serverless 如何使用 Javascript 全局触发自定义事件? - How to trigger a custom event globally using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM