提问人:Max Alexander Hanna 提问时间:9/26/2019 最后编辑:Max Alexander Hanna 更新时间:10/1/2019 访问量:137
IE8 样式不支持 setProperty 方法
IE8 Style Does not support setProperty method
问:
在以下代码行上出现此错误:
document.getElementsByTagName("table")[0].style.setProperty("background-color", "#D19000", "important");
Object doesn't support property or method 'setProperty'
只有在IE8中,去想想,有人知道如何修复它吗?
答:
2赞
scunliffe
9/26/2019
#1
对于旧版本的 Internet Explorer,需要使用以下语法:
elem.style.backgroundColor = "#D19000";
elem.style.color = "red";
请注意,任何连字符的属性都需要采用 camelCase 格式。
评论
0赞
Max Alexander Hanna
9/26/2019
如何将 !important 属性添加到 backgroundColor ?
1赞
scunliffe
9/26/2019
如果我没记错的话,您应该能够将其设置为:。backgroundColor = "#D19000 !important"
评论
... [0].style["backgroundColor"] = "#D19000"
CSSStyleDeclaration.prototype.setProperty = function (name, value, priority) { this[name] = value; };
CSSStyleDeclaration