在大多數瀏覽器(例如Firefox,Opera)上獲取元素的計算後的樣式會返回一個類型爲CSSStyleDeclaration
的漂亮對象。在Chrome 28和PhantomJS 1.9上,我得到一個以編號鍵開頭的對象,其中列出了所有CSS屬性,然後是屬性(對於Chrome)。WebKit/Phantomjs爲什麼getComputedStyles的輸出是這種方式?
例如,在歌劇:
在Chrome中28:
,然後最終你得到有用的部分:
在PhantomJS 1.9它甚至更糟的是,你獲取編號屬性,然後只有兩個命名屬性:lenght和cssText。
...
219: 'glyph-orientation-horizontal',
220: 'glyph-orientation-vertical',
221: '-webkit-svg-shadow',
222: 'vector-effect',
length: 223,
cssText: 'background-attachment: scroll; background-clip: border-box; background-color: rgba(0, 0, 0, 0); background-image: none; background-o...