2017-09-15 39 views
0

如何在單擊子事件時停止父活動觸發器?如何在單擊子div時停止父div觸發器

CODE:

$('body').on('click', 'cs-placeholder', function(e) { 
    //* Disable dropdown in modals that aren't contacts 
    if($(e.target).parents(".modal").length === 0 || $(e.target).parents("#contact").length === 1) { 
     if($(this).hasClass('active')) { 
      alert('close'); 
      $(this).removeClass('active'); 
     } 
    } else { 
     alert('open'); 
     $('.cs-placeholder').removeClass('active'); 
     $(this).toggleClass('active'); 
    } 
} 
+1

在子單擊處理程序中使用'e.stopPropagation()'。 –

+2

發佈你的代碼,而不是你的代碼的圖片。 –

回答

0
$("body").on('click', '.cs-placeholder', function(e) { 
    e.stopPropagation(); 
}); 

如果您想了解更多關於.stopPropagation()

相關問題