首頁  >  事件對像  > eve.isPropagationStopped()

返回值:Boolean event.isPropagationStopped()

V1.3 概述

根據事件對像中是否呼叫過 event.stopPropagation() 方法來返回一個布爾值。

這個事件方法在  W3C DOM Level 3 specification  有介紹。

示例

描述:

檢測 event.stopPropagation() 是否被呼叫過。

程式碼:
<!DOCTYPE html>
  <html>
  <head>
    <script src="//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>