jQuery event.stopPropagation() 方法

jQuery 教程 · 2019-03-11 07:13:48

实例

阻止 click 事件冒泡到父元素:

$("span").click(function(event){
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
$("div").click(function(){
alert("The div element was clicked.");
});

定义和用法

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

提示:请使用 event.isPropagationStopped() 方法来检查指定的事件上是否调用了该方法。

语法


event.stopPropagation()

参数 描述
event 必需。event 参数来自事件绑定函数。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

Elements of Programming

Elements of Programming

Alexander A. Stepanov、Paul McJones / Addison-Wesley Professional / 2009-6-19 / USD 39.99

Elements of Programming provides a different understanding of programming than is presented elsewhere. Its major premise is that practical programming, like other areas of science and engineering, mus......一起来看看 《Elements of Programming》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器