在Firefox,Opera和IE中我可以通过以下方式获取它们:
>> for (k in document.body.style) console.log(k) -> opacity background height textAlign . ... long list ... . pointerEvents
在WebKit中,结果完全不同:
>> for (k in document.body.style) console.log(k) -> cssText length parentRule getPropertyValue getPropertyCSSValue removeProperty getPropertyPriority setProperty item getPropertyShorthand isPropertyImplicit
更新:最新的WebKit确实在HTMLElement.style中枚举CSS属性,与所有浏览器相同.
答案是
>> document.defaultView.getComputedStyle(document.body, '') -> CSSStyleDeclaration 0: "background-attachment" 1: "background-clip" 2: "background-color" 3: "background-image" 4: "background-origin" 5: "background-position" 6: "background-repeat" 7: "background-size" 8: "border-bottom-color" 9: "border-bottom-left-radius" ...
感谢Anton Byrna的解决方案.
一个问题仍然存在:getComputedStyle()
不返回像background
和的快捷方式border
.