在 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 does enumerate over CSS properties in HTMLElement.style所有浏览器都采用相同的方式。
最佳答案
答案是
>> 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 的 solution .
仍然存在一个问题:getComputedStyle()
不返回像 background
和 border
这样的快捷方式。
关于javascript - 如何在 WebKit 中获取所有受支持的 CSS 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2614963/