event.isImmediatePropagationStopped()

event.isImmediatePropagationStopped()返回类型:Boolean

描述: 指示event.stopImmediatePropagation()是否已经在事件对象上调用过了。

此属性是在DOM level 3中引入的。

示例:

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

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.isImmediatePropagationStopped demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<button>click me</button>
<div id="stop-log"></div>
<script>
function immediatePropStopped( event ) {
var msg = "";
if ( event.isImmediatePropagationStopped() ) {
msg = "called";
} else {
msg = "not called";
}
$( "#stop-log" ).append( "<div>" + msg + "</div>" );
}
$( "button" ).click(function( event ) {
immediatePropStopped( event );
event.stopImmediatePropagation();
immediatePropStopped( event );
});
</script>
</body>
</html>

演示: