2013-01-03 3 views
1

이 tv.ui.button은 처음로드 될 때 마우스 커서로만 응답하지만 한 번 이상 클릭 한 후 키보드 ENTER 또는 마우스 클릭에 응답합니다. 내가 여기서 뭔가 잘못 됐니?tv.ui.button 페이지로드시에만 마우스 스틱에 응답

HTML

<div class="tv-button alert-button" id="test-button">Alert button</div> 

JS

decorateHandler.addClassHandler('alert-button', function(button) { 
goog.events.listen(button, tv.ui.Button.EventType.ACTION, 
     function() { 
     alert('Button clicked.'); 
     var elementToFocus = goog.dom.getElement('tab1'); 
     var componentToFocus = tv.ui.getComponentByElement(elementToFocus); 
     tv.ui.Document.getInstance().setFocusedComponent(componentToFocus);; 
     }); 
}); 

편집 : 그것은이 특별히 자바 스크립트에 대한 질문이 아니라 폐쇄 될 수있다 보인다. 적절한 태그 아래에 새로운 질문을 게시하고 있습니다.

답변

1

버튼에 커서 포커스가 있는지 확인 했습니까? 그렇지 않으면 "Enter"키 이벤트가 기본 처리기로 전달됩니다.

+0

잘 모르겠다. 커서 포커스는 어떻게 정의됩니까? – ejfrancis

+0

이 StackOverflow 답변을보십시오 : http://stackoverflow.com/questions/148361/how-can-i-give-keyboard-focus-to-a-div-and-attach-keyboard-event-handlers-to -it – Krispy

+0

tabindex = 0처럼 추가했습니다.

Alert button
아직 행운이 아닙니다. 최소한 한번만 클릭하면 키보드에 반응합니다. – ejfrancis

0

음, 세미 해킹으로 해결했습니다. 나는 $ ('target')을 사용했다. $ (document) .ready 내의 버튼을 클릭하면 클릭 이벤트가 실제로 발생한 것처럼 포커스가 설정된다.