在传播期间修改事件数据 [英] modify event data during propagation

查看:80
本文介绍了在传播期间修改事件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在jQuery事件对象传播DOM时附加数据?要澄清一点,如果你有三个嵌套的div,每个都有一个点击事件监听器,然后点击最内层的div会导致所有三个处理程序被从最内层到最外层(事件传播101)。我想做的是将一些数据添加到每个处理程序中的事件对象,以便下一层可以访问。我怎么做?



谢谢。

解决方案

也许我误解了这个问题,但是我碰到了这个StackOverflow页面,同时寻找一种方法来做同样的事情。



我发现你可以返回要传递的值/值在每个处理程序的末尾,然后使用 event.result 属性访问后续处理程序。



简单演示 http://api.jquery.com/event.result/


Is there any way of attaching data to a jQuery event object as it propagates up the DOM?

To clarify, if you have three nested divs, each with a click event listener, then clicking on the innermost div results in all three handlers being called from the innermost to the outermost (event propagation 101). What I'd like to do is add some data to the event object in each handler that's accessible to the next layer up. How do I do that?

Thanks.

解决方案

Maybe I've misunderstood the question, but I came across this StackOverflow page whilst searching for a way to do the same thing.

I have since found that you can return the value/values that you want to pass at the end of each handler and then access them in subsequent handlers using the event.result property?

Simple demo at http://api.jquery.com/event.result/

这篇关于在传播期间修改事件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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