停止传播所有事件 [英] Stop propagation for all events

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

问题描述

在我当前应用程序遇到的几乎所有事件中,我都会调用e.stopPropagation().有什么方法可以停止每个事件的传播而不必在每个函数体的开头显式调用该方法吗?

I am calling e.stopPropagation() on almost every event that I have for my current application. Is there any way to just stop the propagation for every event without having to explicitly call the method at the start of every function body?

推荐答案

否不能全局声明

event.stopPropagation()方法停止将事件冒泡到父元素,从而阻止执行任何父事件处理程序.

The event.stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed.

例如,如果在DIV或FORM内有一个附加了click方法的链接,并且还附加了click方法,则它将阻止DIV或FORM click方法触发.

For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.

http://api.jquery.com/event.stopPropagation/

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

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