当前位置: 首页 > 文档资料 > jQuery 入门教程 >

isPropagationStopped()

优质
小牛编辑
123浏览
2023-12-01

描述 (Description)

isPropagationStopped()方法检查是否曾在此事件对象上调用event.stopPropagation()。

如果已经调用了event.stopPropagation()方法,则此方法返回true,否则返回false。

语法 (Syntax)

以下是使用此方法的简单语法 -

<i>event</i>.isPropagationStopped() 

参数 (Parameters)

以下是此方法使用的所有参数的说明 -

  • NA

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

<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>