2014-12-05 5 views
1

이 코드는 Esc 키를 누를 때 숨겨져 있었던 상자 div을 숨기지 않습니다.숨기기 요소 누르기 Esc

function Boxup(elementN, event){ 
    $("#"+elementN).css({ 
     "display":"block", 
     "top":event.pageY+"px" , 
     "left":event.pageX+"px"  
    }) 
} 
function hideCurrentPopup(ele){ 
    $(ele).parent().hide(); 
} 

    $(this).keyup(function(event) { 
     if (event.which == 27) { 
      disablePopup(); 
     } 
    }); 

내가 누락 된 것이 있습니까? 코드에서

+2

에 도달하기 위해 어떤 경우에 방지하지 않을 있는지 확인 눌렀을 때, 당신은 "disablePopup"을 호출하지만 예제에는 disablePopup이 없다? – Kolban

+1

또한, 이스케이프 키가'this'에 묶여있는 것처럼 보입니다 ... 다른 코드 안에 있거나'body ''와 같은 것을 연결하고 싶습니까? – rfornal

답변

1

내가 정확히 this이 줄을 참조 무엇을 말할 수 없습니다 : 그것은 this"textarea" 또는 "input"을 의미 원인 해당 요소가 초점가있는 경우

$(this).keyup(function(event) { 

그것이 을 이벤트를 트리거합니다, 그렇지 않은 경우 document

에 의해 등록 된 keyup 이벤트를 찾고 있습니다. 시도해 볼 수있는 내용은 다음과 같습니다.

function Boxup(elementN, event){ 
    $("#"+elementN).css({ 
     display : "block", 
     top : event.pageY , // px are not needed as they are default unit in jQ 
     left : event.pageX  
    }) 
} 

function hideCurrentPopup(ele){ // note your function name and the argument! 
    $(ele).parent().hide();  // (do you need .parent()? I don't know 
}        // without seeing any HTML sample) 

$(document).keyup(function(event) { // document is probably the selector you want 
    if (event.which == 27) { 
     hideCurrentPopup("#hereYourPopupID"); // try alike 
    } 
}); 

추신 : esc 키 인 경우 $(some Selector here).keyup(function(event) {를 사용하여 당신이 버블 DOM 트리에 keyup 이벤트가 귀하의 예제에서 documentElement