jQuery event.stopImmediatePropagation() 方法
实例
执行第一个事件处理程序,并停止执行其余的事件处理程序:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$("div").click(function(event){alert("事件处理 1 已执行");event.stopImmediatePropagation();});$("div").click(function(event){alert("事件处理 2 已执行");});$("div").click(function(event){alert("事件处理 3 已执行");});});</script></head><body><div style="height:100px;width:300px;padding:10px;border:1px solid blue;background-color:lightblue;">点击这个 div 元素</div><p>由于 event.stopImmediatePropagation() 第二次和第三次单击事件将不会执行。试着删除这个方法,看看会发生什么。</p></body></html>
定义与用法
event.stopImmediatePropagation() 方法停止执行其余的事件处理程序。
此方法还阻止事件在 DOM 树中冒泡。
提示: 使用 event.isImmediatePropagationStopped() 方法来检查是否为被事件调用。
语法
event.stopImmediatePropagation()
| 参数 | 描述 |
|---|---|
| event | 必填。event 参数来自事件绑定函数 |