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

Quảng cáo

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>
Quảng cáo

Nó sẽ cho kết quả:

Các bài học jQuery khác tại VietJack:


xu_ly_su_kien_trong_jquery.jsp