为什么我点击按钮或触发事件没有触发事件?我想念什么?
<html>
<head><script src="jquery-1.7.1.js" type="text/javascript"></script>
<script src="underscore.js" type="text/javascript"></script>
<script src="backbone.js" type="text/javascript"></script>
<script type="text/javascript">
var SearchView = Backbone.View.extend({
events: {
"click #testid": 'savenow'
},
initialize: function(){
console.log("init");
console.log($('testid'));
},
savenow: function(){
console.log("test save method");
}
});
// The initialize function is always called when instantiating a Backbone View.
// Consider it the constructor of the class.
var search_view = new SearchView({ el: $('#testid') });
search_view.trigger("savenow", "test");
</script></head>
<body>
<h1>test</h1>
<input id="testid" type="button" value="testbutton" />
</body></html>
上面的示例几乎是复制的,但在我的情况下它不起作用。