knockout.js 文档显示了这样的 css 绑定:
<div data-bind="css: { profitWarning: currentProfit() < 0 }">
Profit Information
</div>
我需要对其进行调整以更改鼠标单击时的 css 类。我怎样才能做到这一点?
根据下面的答案,我正在使用如下代码:
// CSS class to be applied
<style>
.bigclass
{
width: 200px;
}
</style>
// Select list inside a jquery .tmpl
<script id='criteriaRowTemplate' type='text/html'>
<tr>
<td>
<select data-bind='click: makeBig, css: {bigclass : SelectHasFocus() > 0}' />
</td>
</tr>
</script>
// Knockout.js Viewmodel
var CriteriaLine = function() {
this.SearchCriterion = ko.observable();
this.SelectHasFocus = ko.observable(0);
// this method is called
makeBig = function(element) {
this.SelectHasFocus(1);
};
};
但是,这并没有扩大选择列表的宽度。我究竟做错了什么?