jQuery event.stopPropagation() 方法
实例
阻止 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();
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()