isImmediatePropagationStopped()
优质
小牛编辑
129浏览
2023-12-01
描述 (Description)
isImmediatePropagationStopped()方法检查是否曾在此事件对象上调用event.stopImmediatePropagation()。
如果已经调用了event.stopImmediatePropagation()方法,则此方法返回true,否则返回false -
语法 (Syntax)
以下是使用此方法的简单语法 -
<i>event</i>.isImmediatePropagationStopped()
参数 (Parameters)
以下是此方法使用的所有参数的说明 -
NA
例子 (Example)
以下是一个简单的例子,简单地显示了这种方法的用法 -
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("div").click(function(event){
if ( event.isImmediatePropagationStopped() ){
alert( "Event bubbling is disabled - 1" );
}else{
alert( "Event bubbling is enabled - 1" );
}
event.stopImmediatePropagation();
if ( event.isImmediatePropagationStopped() ){
alert( "Event bubbling is disabled - 2" );
}else{
alert( "Event bubbling is enabled - 2" );
}
});
});
</script>
<style>
div{ margin:10px;padding:12px; border:2px solid #666; width:160px;}
</style>
</head>
<body>
<p>Click on any box to see the result:</p>
<div id = "div1" style = "background-color:blue;">
BOX 1
</div>
<div id = "div2" style = "background-color:red;">
BOX 2
</div>
</body>
</html>