CSSStyleDeclaration未找到属性?解决方案:cssText的妙用
最编程
2024-08-10 12:41:39
...
cssText 也是 style: CSSStyleDeclaration
的一个属性,是将 css 压缩成一行之后的结果
style = {
width: "100px";
height: "200px";
cssText: "zoom: 50%;border:1px solid red"
};
- cssText 里可以有多个属性
- cssText 权重比 style.xx 高
- 即使将 style.xx 写在 cssText 后也是如此
- 可能是因为 css 解析的时候是最后解析 cssText 的,将它 Parse 成 Json 缀到后面的
- 为避免 cssText 值被覆盖,应使用 cssText
+=
…,而非 cssText=
…