我是Backbone的新手,理解這個想法,但是在編寫簡單的toggleClass功能時遇到了麻煩。我的網站是一個正方形的網格,當一個廣場有「懸停」的類時,一些CSS導致外觀改變(顯然)。我的問題是toggleClass無法正常工作。我的代碼如下:骨幹 - 懸停的toggleClass
var IndexView = Backbone.View.extend({
el: $('#main'),
indexTemplate: $("#indexSquare").template(),
events: {
"mouseover .square" : "mouseovercard"
},
render: function() {
removeFallbacks();
var sg = this;
this.el.fadeOut('fast', function() {
sg.el.empty();
$.tmpl(sg.indexTemplate, sg.model.toArray()).appendTo(sg.el);
sg.el.fadeIn('fast');
});
return this;
},
mouseovercard: function() {
$(this).toggleClass('hover')
console.log("hey you're hovering!")
}
});
這到底是什麼錯誤?任何幫助都感激不盡!