在包含永恒CSS样式表(通过加载<link rel="stylesheet">
)的网页上,我想修改其CSS规则之一的选择器。我可以参考以下规则:
var rule = document.styleSheets[…].cssRules[…];
(…
数字在哪里)。
选择之后,我可以读取其选择器和其他值:
rule.cssText // 'em { color: red }'
rule.selectorText // 'em'
rule.style.color // 'red'
但是,当我尝试编写其中之一时,它只允许我编写style
对象:
// These won’t work
rule.cssText = 'em.foo { color: red }';
rule.selectorText = 'em.foo';
// This will work
rule.style.color = 'blue';
为什么不让我写信.cssText
或.selectorText
?根据我在规范中看到的内容,它们不是只读的。
更新:我也检查了内联样式表。它也不起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句