event.isPropagationStopped()办法在jQuery中用于查看对象event.stopPropagation()是否被调用。如果event.stopPropagation()被调用, 则返回true, 否则返回false。
语法如下:
event.isPropagationStopped()
参数:它蕴含单个参数事件这是强制性的。此参数来自事件绑定性能。
范例1:本示例应用event.isPropagationStopped()办法查看event.stopPropagation()是否被调用。
<!DOCTYPE html>
<html>
<head>
<script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$("button").click(function(event) {
event.stopPropagation();
alert("Is event.stopPropagation() called: "
+ event.isPropagationStopped());
});
});
</script>
</head>
<body>
<h1>
jQuery event.isPropagationStopped() Method
</h1>
<p>
click on button to check if the
event.stopPropagation() is called.
</p>
<button>Check</button>
</body>
</html>
输入如下:
单击按钮之前:
单击按钮后:
范例2:本示例应用event.isPropagationStopped()办法查看event.stopPropagation()是否被调用。
<!DOCTYPE html>
<html>
<head>
<title>
event.isPropagationStopped method
</title>
<script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body>
<h1>
jQuery event.isPropagationStopped() Method
</h1>
<p>
click on button to check if the
event.stopPropagation() is called.
</p>
<button>Check</button>
<div id = "GFG"></div>
<script>
function propStopped( event ) {
var msg = "";
if ( event.isPropagationStopped() ) {
msg = "True";
}
else {
msg = "False";
}
$( "#GFG" ).append( "<div>" + msg + "</div>" );
}
$( "button" ).click(function(event) {
propStopped( event );
propStopped( event );
event.stopPropagation();
propStopped( event );
});
</script>
</body>
</html>
输入如下:
单击按钮之前:
单击按钮后:
更多前端开发相干内容请参考:lsbin – IT开发技术:https://www.lsbin.com/
查看相干的jQuery内容:
- jQuery刷新页面:https://www.lsbin.com/2951.html
- jQuery抉择文本节点:https://www.lsbin.com/2680.html
- jQuery更改占位符文本:https://www.lsbin.com/1756.html
发表回复