jQuery事件冒泡 [英] jQuery event bubbling

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

问题描述

我想了解如何解释冒泡。这是否意味着上升HTML代码层次结构或其他什么?

I want to understand how exactly to interpret bubbling. Does it mean going up the HTML code hierarchy or something else?

其次,我正在经历一个示例我无法理解它所说的最后一部分

Secondly, I was going through an example and I could not understand the last part where it says


基于P的点击处理程序侦听click事件,然后阻止它传播(冒泡)

The P-based click handler listens for the click event and then prevents it from being propagated (bubbling up)

这是什么意思?

推荐答案

return false;

将阻止冒泡。它用于停止默认操作,例如选中复选框,打开选择,点击等。

will prevent "bubbling". It's used to stop default actions like checking a checkbox, opening a select, a click, etc.


阻止更多处理程序在执行后执行使用.live(),
绑定处理程序必须返回false。调用.stopPropagation()将不会
完成此操作。

To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this.

来自 jQuery中的注意事项.live()



推理(感谢@AlienWebguy):

From Caveats in jQuery .live()


Reasoning (thanks to @AlienWebguy):

原因 stopPropagation()不适用于 live() live()将事件绑定到文档,因此当它触发时,没有其它地方可以传播。

The reason stopPropagation() doesn't work with live() is that live() binds the event to document so by the time it fires there's no where else for it to propagate.

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

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