event.isPropagationStopped()

event.isPropagationStopped() 官网原E文: Boolean

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

  • version added: 1.3event.isPropagationStopped()

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

Example:

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

Demo:

jQuery 1.6 API 中文版Clove整理、修订