2014-02-13 4 views
0

이 질문은 여러 번 질문되었지만 답변을 얻을 수 없습니다.div를 한번 클릭하시면 바깥 쪽을 클릭하면 알 수 없습니다.

<a href="#" id='link'>Click here to show div</a> 

JS :

$('#link').click(function(e) { 
    $('div.termifier').remove(); 
    $('<div>').addClass('termifier').css({ 
     position: 'absolute', 
     top: event.pageY , 
     left: event.pageX , 
     display: 'none' 
     }).appendTo('body') 
    .append(
     $('<div>').html("termifier") 
    ); 
    $('div.termifier').fadeIn('slow'); 
}); 

$('html').click(function() { 
    $('div.termifier').fadeOut(); 
}); 

$('div.termifier').click(function(e){ 
    e.stopPropagation(); 
}); 

CSS 나는 링크 에 클릭이 그런 DIV, 그것의 외부를 클릭

my code

HTML을 숨기기 때 사업부가 표시되고 싶어요

div.termifier { 
    background-color: cornsilk; 
    width: 256px; 
    color: brown; 
    padding: 8px; 
    font-size: 0.8em; 
} 
0 당신이 사업부의 aswell을 클릭하면 페이드를 방지하려면

답변

1

사용 e.stopPropagation()

$('#link').click(function(e) { 
    e.stopPropagation(); 
    /* Rest of the code for clicking */ 
}); 

DEMO

, 이렇게 다음과 같은 경우는 .on() 대신 .bind()을 사용할 수 있습니다

$(document.body).bind('click','.termifier',function(e){ 
    e.stopPropagation(); 
}); 

jQuery의 최신 버전을 1.6.4보다 사용했습니다.

DEMO

+0

여전히 작동하지 않음 – naser

+0

@naser 작동하지 않는 이유 ....? – Anton

+0

링크를 클릭하면 div가 표시되지 않습니다. – naser

관련 문제