isPropagationStopped()方法检查是否曾经在此事件对象上调用过event.stopPropagation()。
如果已经调用 event.stopPropagation()方法,则此方法返回true,否则返回false。
event.isPropagationStopped()
以下是一个简单的示例,简单说明了此方法的用法-
<html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function(event){ alert("This is : " + $(this).text()); if ( event.isPropagationStopped() ){ alert( "Event bubbling is disabled - 1" ); }else{ alert( "Event bubbling is enabled - 1" ); } event.stopPropagation(); if ( event.isPropagationStopped() ){ alert( "Event bubbling is disabled - 2" ); }else{ alert( "Event bubbling is enabled - 2" ); } }); }); </script> <style> div{ margin:10px;padding:12px; border:2px solid #666; width:160px;} </style> </head> <body> <p>Click on any box to see the effect:</p> <div id="div1" style="background-color:blue;"> OUTER BOX <div id="div2" style="background-color:red;"> INNER BOX </div> </div> </body> </html>
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/events-ispropagationstopped.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)