我试图将点击事件处理程序添加到我的主干javascript文件中。但它显示一个错误:“未捕获的TypeError:无法读取未定义的属性'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();

最佳答案

var SongView = Backbone.Model.extend({


应该

var SongView = Backbone.View.extend({

关于javascript - Backbone JS Click事件处理程序不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58427297/

10-10 04:50