我尝试了以下代码,使用google closure-library监听关键事件,但代码不起作用。
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')});
答案 0 :(得分:3)
你必须在相关的DOM元素上听取事件:
goog.events.listen(myField.getElement(), goog.events.EventType.KEYPRESS, function(){alert('12')});