我试图将click事件处理程序添加到我的 Backbone javascript文件中。但是它显示了一个错误:“未捕获的类型错误:无法读取未定义的属性'html'。”以下是代码。如有任何帮助,将不胜感激。main.js文件
var Song = Backbone.Model.extend();
var SongView = Backbone.Model.extend({
events: {
"click": "onClick",
"click .bookmark": "onClickBookmark"
},
onClick: function(){
console.log("Listen Clicked");
},
onClickBookmark: function(e){
e.stopPropagation();
console.log("Bookmark Clicked");
},
render: function(){
this.$el.html(this.model.get("title") + " <button>Listen</button> <button class='bookmark'> Bookmark</button>");
return this;
}
});
var song = new Song({title: "sky is sdv sv"});
var songView = new SongView({el: "#container", model: song});
songView.render();
1条答案
按热度按时间rhfm7lfc1#
应该是