2012-12-11 90 views
0

我試着用下面的代碼來監聽使用google閉包庫的關鍵事件,但代碼不起作用。關閉庫密鑰事件監聽不起作用

goog.require('goog.events.EventHandler'); 
goog.require('goog.events.EventType'); 
goog.require('goog.dom'); 
goog.require('goog.editor.Command'); 
goog.require('goog.editor.Field'); 
goog.require('goog.editor.Field.EventType'); 

-----------------------below--not worked------------------------------------------ 

var myField = new goog.editor.Field('editMe'); 

goog.events.listen(myField, goog.events.EventType.KEYPRESS, 
     function(){alert('12')}); 

回答

2

你必須傾聽相關的DOM元素的事件:

goog.events.listen(myField.getElement(), goog.events.EventType.KEYPRESS, function(){alert('12')});