取消事件冒泡(多个事件重复发生)
来源:互联网 发布:2016淘宝联盟导购推广 编辑:程序博客网 时间:2024/05/15 08:26
在默认情况下,发生在一个子元素上的单击事件(或者其他事件),如果在其父级元素绑定了一个同样的事件,此时点击子元素,click
事件会首先被子元素捕获,执行绑定的事件程序,之后会被父级元素捕获,再次激发一段脚本的执行,这就是所谓的“事件冒泡”。
在通常情况下,我们只希望事件发生在它的目标而并非它的父级元素上,只需加个stopBubble
方法,即可取消事件冒泡,见下:
现在你可能想知道,什么时候需要阻止事件冒泡?事实上,现在绝大多数情况下都可以不必在意它。但是当你开始开发动态应用程序(尤其是需要处理键盘和鼠标)的时候,就有这个必要了。
英文参考:
cancelBubble Property
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers.
Syntax
event.cancelBubble [ = bCancel ]
Possible Values
bCancelBoolean that specifies or receives one of the following values.falseDefault. Bubbling is enabled, allowing the next event handler in the hierarchy to receive the event. trueBubbling is disabled for this event, preventing the next event handler in the hierarchy from receiving the event.The property is read/write. The property has a default value of false.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see About Dynamic Properties.
Remarks
Using this property to cancel bubbling for an event does not affect subsequent events.
Example
This example cancels bubbling of the onclick event if it occurs in the img object when the user presses the SHIFT key. This prevents the event from bubbling up to the onclick event handler for the document.
Standards Information
There is no public standard that applies to this property.
- 取消事件冒泡(多个事件重复发生)
- 取消事件的发生
- 阻止冒泡事件发生
- js取消事件冒泡
- js 取消冒泡事件
- javascript_取消事件冒泡
- js取消事件冒泡
- 取消冒泡事件方法
- 取消事件冒泡
- jQuery取消事件冒泡
- JQuery取消事件冒泡
- JQuery取消事件冒泡
- 取消事件的冒泡
- JS取消冒泡事件
- 取消事件冒泡-select模拟(多选)
- 取消事件冒泡(大小DIV)
- js取消事件冒泡方法
- jQuery取消冒泡排序事件
- Php采集让你的站跟新浪网的新闻保持同步.doc
- 导师见面会之一(第3次报告)
- 我用div+css技术来重新编写网站页面的体会
- string 与 vector及容器操作的异同
- string 字符串处理几点收获
- 取消事件冒泡(多个事件重复发生)
- POJ 2109
- 用WINSOCK API实现同步非阻塞方式的网络通讯
- Mac 下制作 安装包
- Datalist内嵌与递归的用法分析
- Symbian中使用位图的两种方法
- datalist内嵌与递归的前台代码
- 蒋会成,请珍惜倒追你的女孩
- ASP.NET URL双向改写的实现