通过css绑定,knockout.js组合动态和静态类 [英] combine dynamic and static classes through css binding, knockout.js
本文介绍了通过css绑定,knockout.js组合动态和静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在knockout.js中我们可以对静态类使用css绑定
In knockout.js we can use css binding for static classes
<div data-bind="css: {'translucent ': number() < 10}">static dynamic css classes</div>
和动态
<div data-bind="css: color">static dynamic css classes</div>
我试过 http://jsfiddle.net/tT9PK/1/ 将它组合成类似
css: {color, translucent: number() < 10}
获取动态类颜色
和静态半透明
但同时出现错误。有没有办法做到这一点?
to get dynamic class color
and static translucent
at the same time, but I get an error. Is there a way to do that?
推荐答案
你可以通过 css $ c添加动态类$ c>属性然后按
attr
属性添加静态类
You can add dynamic class by css
property and then add static class by attr
property
<div data-bind="attr: { 'class': color }, css: { 'translucent': number() < 10 }">
static dynamic css classes
</div>
请务必为此绑定添加任何预定义类
attr :{'class':color}
Be sure to add any predefined classes to this binding
attr: { 'class': color }
这篇关于通过css绑定,knockout.js组合动态和静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文