使用jQuery获取* all * CSS属性

以下是使用jQuery获取一个css属性的方法:

$('someObject').css('attribute')

你怎么得到它们的? (没有指定,最好是以下格式,以便以后可以用jQuery重新应用):

  cssObj = { 'overflow':'hidden', 'height':'100%', 'position':'absolute', } 

谢谢!!

编辑

我想要获取的方法在样式表中声明(它们不是内联的)。 很抱歉没有说明。

这样的事情怎么样:

jQuery CSS插件返回计算的元素样式到伪克隆那个元素?

这很难看,但它似乎适用于海报……

这也可能是有趣的: https : //developer.mozilla.org/en/DOM : window.getComputedStyle

使用jQuery属性选择器查看此实例

 $(document).ready(function() { alert($("#stylediv").attr('style')); });​ 

不确定这是一个跨浏览器,但它适用于Chrome –

https://gist.github.com/carymrobbins/223de0b98504ac9bd654

 var getCss = function(el) { var style = window.getComputedStyle(el); return Object.keys(style).reduce(function(acc, k) { var name = style[k], value = style.getPropertyValue(name); if (value !== null) { acc[name] = value; } return acc; }, {}); }; 

window.getComputedStyle(元件);

 // For example var element = document.getElementById('header'); window.getComputedStyle(element);