返回值:Booleanevent.isPropagationStopped()

V1.3概述

根据事件对象中是否调用过 event.stopPropagation() 方法来返回一个布尔值。

这个事件方法在 W3C DOM Level 3 specification 有介绍。

示例

描述:

检测 event.stopPropagation() 是否被调用过。

代码:
<!DOCTYPE html>

  <html>

  <head>

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>

  </head>

  <body>

        <button>click me</button>

    <div id="stop-log"></div>

      <script>

    function propStopped(e) {

    var msg = "";

    if ( e.isPropagationStopped() ) {

      msg =  "called";

    } else {

      msg = "not called";

    }

    $("#stop-log").append( "<div>" + msg + "</div>" );

  }

    $("button").click(function(event) {

    propStopped(event);

    event.stopPropagation();

    propStopped(event);

  });

    </script>

    </body>

  </html>
<<返回首页<<返回首页