【发布时间】:2017-10-30 03:45:34
【问题描述】:
knockout.js中css-binding的文档提供了一个示例如下:
<div data-bind="css: { profitWarning: currentProfit() < 0 }">
Profit Information
</div>
<script type="text/javascript">
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
</script>
这个例子似乎应用了“profitWarning” currentProfit 是负数。我想稍微改变一下,并在单击 div 时应用此类。如何将“单击”条件应用于此示例?另外,我想制作多个 div 并一次只应用一个样式(单击 div 时应用样式,单击另一个 div 时将其删除)
谢谢
【问题讨论】:
标签: javascript html css knockout.js