isPropagationStopped() trong jQuery
Miêu tả
Phương thức isPropagationStopped() trong jQuery kiểm tra có hay không event.stopPropagation() đã từng được gọi trên đối tượng Event này.
Phương thức này trả về true nếu event.stopPropagation() đã được gọi, nếu không là false.
Cú pháp
Sau đây là cú pháp để sử dụng isPropagationStopped() trong jQuery:
event.isPropagationStopped()
Tham số
Chi tiết tham số được sử dụng trong phương thức isPropagationStopped() trong jQuery:
NA
Ví dụ
Ví dụ đơn giản sau minh họa cách sử dụng của isPropagationStopped() trong jQuery.
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://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){
alert("This is : " + $(this).text());
if ( event.isPropagationStopped() ){
alert( "Event bubbling is disabled - 1" );
}else{
alert( "Event bubbling is enabled - 1" );
}
event.stopPropagation();
if ( event.isPropagationStopped() ){
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 effect:</p>
<div id="div1" style="background-color:blue;">
OUTER BOX
<div id="div2" style="background-color:red;">
INNER BOX
</div>
</div>
</body>
</html>
Nó sẽ cho kết quả:
Công cụ giáo viên (2048.VN)
Tạo- trộn đề thi miễn phí từ file PDF, Word, Giao bài nhanh chóng, Hoàn toàn Free
Các bài học jQuery khác tại VietJack:
Dành cho bạn
Công cụ giáo viên
- Tạo đề online từ PDF / Word
- Trộn nhiều mã đề, in Offline
- Giao bài online, Quản lí lớp học

