加载中...

event.isPropagationStopped()


概述

返回值:Boolean

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

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

示例

实例

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

代码:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  5. </head>
  6. <body>
  7. <button>click me</button>
  8. <div id="stop-log"></div>
  9. <script>
  10. function propStopped(e) {
  11. var msg = "";
  12. if ( e.isPropagationStopped() ) {
  13. msg = "called";
  14. } else {
  15. msg = "not called";
  16. }
  17. $("#stop-log").append( "<div>" + msg + "</div>" );
  18. }
  19. $("button").click(function(event) {
  20. propStopped(event);
  21. event.stopPropagation();
  22. propStopped(event);
  23. });
  24. </script>
  25. </body>
  26. </html>

运行一下


还没有评论.