【问题标题】:JavaScript only displays browser specific CSS prefixes even when others are addedJavaScript 仅显示浏览器特定的 CSS 前缀,即使添加了其他前缀
【发布时间】:2013-02-14 08:00:22
【问题描述】:

我正在通过 Javascript 将 CSS 规则直接添加到样式表中:

document.styleSheets[0].cssRules[4].style.borderRadius="10px";
document.styleSheets[0].cssRules[4].style.webkitBorderRadius="10px";
document.styleSheets[0].cssRules[4].style.mozBorderRadius="10px";

我需要稍后显示这些规则:

document.write(document.styleSheets[0].cssRules[4].cssText);

但每个浏览器只显示自己的前缀,例如,当我在 Chrome 上时,我只得到:

-webkit-border-radius:10px;

当我使用 Firefox 时,我只得到:

-moz-boder-radius:10px;

无论我使用什么浏览器,如何将它们全部显示出来?

PS:我不能使用document.getElementById("foo").style.width;之类的东西来显示CSS,必须使用styleSheets[]cssRules[]

【问题讨论】:

  • 这就是为什么它被称为浏览器特定前缀

标签: javascript html css browser vendor-prefix


【解决方案1】:

你不能,因为它们不存在。浏览器会忽略它无法识别的样式,因此不会将它们添加到样式表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2014-01-07
    • 1970-01-01
    • 2012-09-29
    • 2019-05-13
    相关资源
    最近更新 更多