返回值:Booleanevent.isPropagationStopped()
V1.3jQuery event.isPropagationStopped() 方法概述
根據(jù)事件對象中是否調(diào)用過 event.stopPropagation() 方法來返回一個布爾值。
這個事件方法在 W3C DOM Level 3 specification 有介紹。
示例
描述:
檢測 event.stopPropagation() 是否被調(diào)用過。
代碼:
<!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>