事件捕获,事件冒泡和jQuery.on() [英] Event Capturing, Event Bubbling and jQuery.on()

查看:236
本文介绍了事件捕获,事件冒泡和jQuery.on()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于事件捕获冒泡 jQuery.on()的有趣问题。

I have an interesting question about event capturing, bubbling and jQuery.on().

我最近学到了更多关于事件捕获和事件冒泡之间的区别以及两者如何以不同的方式进出DOM中的子父元素。

I have recently learned more about the difference between event capturing and event bubbling and how the two flow differently in and out of the child-parent elements within the DOM.

所以要添加一个带有事件捕获方向的事件监听器,我会使用:

So to add an event listener with "event capture direction" i would use:

element.addEventListener(click,myFunction,true);

并使用添加事件监听器事件泡沫方向我会使用:

element.addEventListener(click,myFunction,false);

这一切都很好,但我想知道的是使用 jquery.on()添加事件监听器,如何根据捕获和冒泡来指定事件方向?

This is all good and well, but what I want to know is when using jquery.on() to add event listeners, how does one specifiy the event direction in terms of capturing and bubbling?

目前我使用的是:

$('父选择器')。on('click','child selector',function(){alert('只是提醒一些事情......' );}};

如何告诉jQuery需要在事件捕获方向添加这些事件监听器事件冒泡方向

How do I tell jQuery that it needs to add these event listeners in the "event capture direction" or the "event bubble direction"?

推荐答案

你做不到。 jQuery事件与事件冒泡一起使用它不支持捕获。

You can't. jQuery events works with event bubbling it doesn't support capturing.

另见

  • Why does jQuery event model does not support event Capture and just supports event bubbling

这篇关于事件捕获,事件冒泡和jQuery.on()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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