2013-08-18 2 views
0

mouseup 함수를 구현하려고합니다. 컨테이너 외부의 아무 곳이나 클릭하면 함수가 발생합니다. 아래 스크립트를 참조하십시오.div의 바깥 쪽을 클릭하면 mouseup 함수가 발생합니다.

이 기능은 잘 작동하지만 페이지의 아무 곳이나 클릭하면 발생합니다.

'if'조건을 만들려고합니다. 마우스 클릭이 함수에 포함 된 컨테이너 또는 그 자손 중 하나에있는 경우 mouseup 함수가 발생하지 않습니다.

아무도 왜 제대로 작동하지 않는지 말할 수 있습니까? 많은 감사 ..

스크립트 :

$(document).mouseup(function (e) 
{ 
var container = $('#containerprA'); 
var containerSW = $('#containerSW'); 


if (!container.is(e.target) // if the target of the click isn't the container... 
    && container.has(e.target).length === 0); // ... nor a descendant of the container 

if (!containerSW.is(e.target) // if the target of the click isn't the container... 
    && containerSW.has(e.target).length === 0) // ... nor a descendant of the container 

{ 
     container.fadeOut('slow',function(){ 
     containerSW.fadeIn('slow'); 
    }); 
} 
}); 
+0

가 jsfiddle을 감사합니다,이 도움이

$(document).ready(function(){ $('#containerSW').hide(); $(document).on('mouseup', function(e) { if (!$(e.target).is('#containerprA') && !$(e.target).parents().is('#containerprA')) { $('#containerprA').fadeOut("slow"); $('#containerSW').fadeIn('slow'); } }); }); 

희망을 시도? – twinlakes

답변

관련 문제