我有关于样式绑定的问题.是否可以生成整个样式绑定文本?财产和价值部分在一起?例如:
function ViewModel() {
this.fontSize = ko.observable(12);
this.fontSizeCSS = ko.computed(function() {
return "font-size: " + " " + this.fontSize() + "px";
}, this);
}
// Activates knockout.js
ko.applyBindings(new ViewModel());
Run Code Online (Sandbox Code Playgroud)
简单的方法是这样做:
<div data-bind="style: { fontSize: fontSize() + 'px'}">
<p>Lorem ipsum</p>
</div>
Run Code Online (Sandbox Code Playgroud)
有可能这样做(我试过,它没有用):
<div data-bind="style: { fontSizeCSS() }">
<p>Lorem ipsum</p>
</div>
Run Code Online (Sandbox Code Playgroud)
如果有,怎么样?如果没有,为什么不呢?可以对html样式元素进行文本绑定,但我想知道你是否可以做一些类似的,我提议的内容?谢谢!
knockout.js ×1