敲除 css 绑定不分配任何 class
knockout css binding not assigning any class
我正在尝试根据布尔值动态设置 class。
我的标记如下所示:
<input
data-bind="
css: {
'chkBxEdit': gThirdCheckboxEnabled(),
'chkBx': !gThirdCheckboxEnabled()
},
enable: gThirdCheckboxEnabled" />
此代码未添加 class,但启用绑定有效
css 绑定工作正常:
var viewmodel = function(){
var self = this;
this.gThirdCheckboxEnabled = ko.observable(false);
this.change = function(){
self.gThirdCheckboxEnabled(!self.gThirdCheckboxEnabled());
};
};
ko.applyBindings(new viewmodel());
.chkBxEdit{
background-color: blue;
}
.chkBx{
background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<input data-bind="css: { 'chkBxEdit': gThirdCheckboxEnabled(), 'chkBx': !gThirdCheckboxEnabled() }" />
<button data-bind="click: change">Change</button>
我正在尝试根据布尔值动态设置 class。 我的标记如下所示:
<input
data-bind="
css: {
'chkBxEdit': gThirdCheckboxEnabled(),
'chkBx': !gThirdCheckboxEnabled()
},
enable: gThirdCheckboxEnabled" />
此代码未添加 class,但启用绑定有效
css 绑定工作正常:
var viewmodel = function(){
var self = this;
this.gThirdCheckboxEnabled = ko.observable(false);
this.change = function(){
self.gThirdCheckboxEnabled(!self.gThirdCheckboxEnabled());
};
};
ko.applyBindings(new viewmodel());
.chkBxEdit{
background-color: blue;
}
.chkBx{
background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<input data-bind="css: { 'chkBxEdit': gThirdCheckboxEnabled(), 'chkBx': !gThirdCheckboxEnabled() }" />
<button data-bind="click: change">Change</button>