如何在WebKit中获取所有受支持的CSS属性?

时间:2010-04-10 21:01:51

标签: javascript css dom webkit

在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所有浏览器都这样做。

2 个答案:

答案 0 :(得分:6)

答案是

>> 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()不会返回backgroundborder等快捷方式。

答案 1 :(得分:1)

我不确定Javascript访问权限,但您可以在此处查找所有受支持的属性(甚至是所有者):CSS property names

相关问题