我开始使用 Backbone.js 并尝试使用 javascript 做一些简单的事情,即显示/隐藏 div。我可以显示 div 但我无法隐藏它,我尝试了很多东西,知道吗?还是可以更复杂?
var Step1View = Backbone.View.extend({
el: $('body'),
events: {
'click #more': 'more',
'click #hide': 'hide',
},
initialize: function (){
_.bindAll(this, 'render', 'more', 'next', 'less');
this.render();
},
render: function (){
var self = this;
$(this.el).append("<a id='more'>Show more</a>");
$(this.el).append("<div id='show' style='display: none'>Div12</div>");
return this;
},
more: function (){
$('#more').text('Hide more');
$('#more').attr('id', '#hide');
$('#show').show();
},
less: function (){
$('#hide').text('Show more');
$('#show').hide();
},
});
干杯