2011-12-24 56 views
2

我想获得应用于元素的所有样式,例如您在右上角看到的名为“计算样式”的Chrome开发人员工具中,我想要获取所有列表简单的方式让所有的名单和财产获取元素的所有计算样式

Source Code

我想这JavaScript,但它不是我想要的,我必须手动写CSS属性

我只是想应用到所有样式元素更早或默认

+0

http://stackoverflow.com/questions/754607/can-jquery-get-all-css-styles-associated-with-an-element – 2011-12-24 17:22:08

+0

的可能重复我没有得到任何解决方案,所以我创建了我自己的 – mikul 2011-12-24 17:24:40

+0

看起来像这样回答你的问题:http://stackoverflow.com/a/5830517/522877 – Wex 2011-12-24 18:03:32

回答

1

尝试使用此功能(updated your jsFiddle);

function getComputedStyle(elm, style) { 
    var computedStyle; 
    if (typeof elm.currentStyle != "undefined") { 
     computedStyle = elm.currentStyle; 
    } 
    else { 
     computedStyle = document.defaultView.getComputedStyle(elm, null); 
    } 
    return computedStyle[style]; 
} 

getComputedStyle()功能是从I does Javascript!

+1

jQuery'css'函数也实现了这个功能,包括更多的“钩子”来处理浏览器的不一致问题。 – 2011-12-24 18:12:49