2013-01-03 21 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);; 
     }); 
}); 

編輯:看來這可能是一個關於JavaScript的問題,而不是關閉特別。我在相應的標籤下發布了一個新問題

回答

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 - 我 – Krispy

+0

我加了tabindex = 0像這樣

Alert button
仍然沒有運氣,它只響應鍵盤後至少點擊一次 – ejfrancis

0

那麼,我用半黑客來修復它。我使用了一個$('target')。點擊$(document).ready中的按鈕,這似乎將焦點設置爲實際發生點擊事件