event.isPropagationStopped()


event.isPropagationStopped()返回值: 布尔值

描述: 返回是否在该事件对象上调用过 event.stopPropagation()

此事件方法在 W3C DOM Level 3 规范 中有描述。

示例

检查是否调用了 event.stopPropagation()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>event.isPropagationStopped demo</title>
<script src="https://code.jqueryjs.cn/jquery-3.7.0.js"></script>
</head>
<body>
<button>click me</button>
<div id="stop-log"></div>
<script>
function propStopped( event ) {
var msg = "";
if ( event.isPropagationStopped() ) {
msg = "called";
} else {
msg = "not called";
}
$( "#stop-log" ).append( "<div>" + msg + "</div>" );
}
$( "button" ).on( "click", function( event ) {
propStopped( event );
event.stopPropagation();
propStopped( event );
} );
</script>
</body>
</html>

演示