我为我的主视图创建了一个模板文件 home.html,其中有一个复选框:
<input type="checkbox" id="chkcompareitem" class="chkcompareitem" />
<input type="button" id="compareitem" class="compareitem" value="Compare items" />
这里的 View :
var HomeView = Backbone.View.extend({
initialize: function() {
},
events : {
'click #chkcompareitem' : 'addItemtoCompareLS'
},
addItemtoCompareLS : function(e){
if(e.currentTarget.checked){
item1.addnewitem(newItem);
item1.disableCompareBtn();
}
},
render : function(){
this.$el.html(homeTemplate);
item1.disableCompareBtn();
}
});
return HomeView;
addnewitem
方法用于将新项目添加到 localStorage。
此处disableCompareBtn()
:
if(compareitems == null || compareitems.length < 2){
$('#compareitem').prop('disabled', true);
}else{
$('#compareitem').prop('disabled', false);
}
问题:当我选中该复选框时,项目已添加到 localStorage,但即使 localStorage 的长度 > 2,按钮仍处于禁用状态。
最佳答案
也许你可以用它来代替 Prop 。
$('#compareitem').attr("已禁用","已禁用");//用于添加禁用属性
和 $('#compareitem').removeAttr("禁用");//用于删除禁用属性
关于javascript - oncheck 复选框显示主干中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20605229/