I'm trying to capture the key event from a view as follows:
myView = Backbone.View.extend({
el: $('#someDiv'),
initialize: function(){
// initialize some subviews
},
render: function(){
return this;
},
events:{
'keypress #someDiv': 'showKey'
},
showKey: function(e){
console.log(e.keyCode);
}
})
That does not work ?
ps: There a no [input] elements in the view or its subviews. I just need to know if the user presses any key and then do something on the view.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…