CSS
css绑定是添加或删除一个或多个CSS class到DOM元素上。如下代码:
<div data-bind="css: { profitWarning: currentProfit() < 0 }">
Profit Information
</div>
var viewModel = {
currentProfit: ko.observable(150000)
// Positive value, so initially we don't apply the "profitWarning" class
};
viewModel.currentProfit(-50);
// Causes the "profitWarning" class to be applied
效果就是当currentProfit小于0的时候,添加profitWarning CSS class到元素上,如果大于0则删除这个CSS class。