我在普通的html文件中测试js脚本
$(document).ready ->
$("#subject").keyup (event) ->
alert "wll"
有用。
但是当我在 emberjs + rails 项目中使用它时。这没用
那是怎么回事?
我在普通的html文件中测试js脚本
$(document).ready ->
$("#subject").keyup (event) ->
alert "wll"
有用。
但是当我在 emberjs + rails 项目中使用它时。这没用
那是怎么回事?
有一条规则:您应该将所有事件放入您的views
( http://emberjs.com/guides/views/ )。
那里有所有事件的列表:
EVENT NAMES
Possible events names for any of the responding approaches described above are:
Touch events:
touchStart
touchMove
touchEnd
touchCancel
Keyboard events
keyDown
keyUp
keyPress
Mouse events
mouseDown
mouseUp
contextMenu
click
doubleClick
mouseMove
focusIn
focusOut
mouseEnter
mouseLeave
Form events:
submit
change
focusIn
focusOut
input
HTML5 drag and drop events:
dragStart
drag
dragEnter
dragLeave
drop
dragEnd
这是一个简单的例子,你可以如何使用它:
<script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<div class='box'>Test</div>
</script>
App = Ember.Application.create({});
App.IndexView = Ember.View.extend({
// This is only for set the focus on our view.
didInsertElement: function() {
return this.$().attr({ tabindex: 1 }), this.$().focus();
},
keyPress: function(event) {
console.log("KeyCode: " + event.keyCode);
},
});
使用视图你可以简单地做到这一点
AView = Ember.View.extend({
keyUp: function(event){
alert('wll');
}
});