【问题标题】:IE8 Style Does not support setProperty methodIE8 Style 不支持 setProperty 方法
【发布时间】:2019-10-01 20:56:03
【问题描述】:

在这行代码上得到这个错误:

document.getElementsByTagName("table")[0].style.setProperty("background-color", "#D19000", "important");

对象不支持属性或方法'setProperty'


只有在 IE8 中,去看看,有人知道如何修复它吗?

【问题讨论】:

  • 或许可以试试... [0].style["backgroundColor"] = "#D19000"
  • 可以使用 polyfill CSSStyleDeclaration.prototype.setProperty = function (name, value, priority) { this[name] = value; };,因为 CSSStyleDeclaration 在这里,似乎

标签: javascript internet-explorer-8 internet-explorer-7


【解决方案1】:

对于旧版本的 Internet Explorer,您需要使用以下语法:

elem.style.backgroundColor = "#D19000";
elem.style.color = "red";

请注意,任何带有连字符的属性都需要采用驼峰命名法。

【讨论】:

  • 如何将 !important 属性添加到 backgroundColor 中?
  • 如果我没记错的话,您应该可以将其设置为:backgroundColor = "#D19000 !important"
猜你喜欢
  • 2014-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-30
  • 2013-08-03
  • 1970-01-01
  • 2011-06-28
  • 1970-01-01
相关资源
最近更新 更多