2014-04-25 1 views
0

내 질문이 하나의 역이라고 생각 클릭 발사에서 클릭 핸들러 : Prevent execution of parent event handler방지 내부 사업부가

내가 Google 애플리케이션 스크립트에서 UI를 짓고 있어요. 큰 컨테이너 div 안에 선택 상자가 있습니다. 부모 div를 클릭 할 때 jQuery를 사용하여 애니메이션을 실행할 수 있기를 원하지만 선택 상자를 클릭 할 때 애니메이션을 실행하지 않으려합니다. stopPropagation을 사용하여 시도했지만 도움이되지 않습니다. 현재 애니메이션 사업부 자체, 또는 선택 드롭 다운 중 하나를 클릭 할 때 실행 :

var ISDOWN = true; //global to track whether div is down or up 

    $("#outer-container").click(
    function(e) { 
    e.stopPropagation(); 
    var source = $(this).attr('id'); 
    if (source === "outer-container"){ 
     if (ISDOWN === true){ 
     $("#outer-container").animate({top: "8px"}); 
      ISDOWN = false; 
     } 
     else { 
     $("#outer-container").animate({top: "45px"}); 
      ISDOWN = true; 
     } 
    } 
    }); 
+0

당신이 원하는 경우 컨테이너에 버블 링되지 않도록'select'를 클릭하면 클릭 핸들러를'select'에 연결하고'stopPropagation'을 호출 할 것입니다. –

답변

0

당신은 요소를 확인할 수 있습니다 이벤트 객체의 target 속성에서 클릭하고

if ($(e.target).attr('id') === 'outer-container') { 
    if (ISDOWN === true){ 
    $("#outer-container").animate({top: "8px"}); 
     ISDOWN = false; 
    } 
    else { 
    $("#outer-container").animate({top: "45px"}); 
     ISDOWN = true; 
    } 
} 
+0

그랬어. 감사! –