我如何得到所有的元素CSS属性的列表与jQuery? [英] How can I get list of all element css attributes with jQuery?
问题描述
我需要获取所有css属性的元素列表。
复制来源 SO1004475 - jQuery CSS插件返回计算的元素样式以伪元素克隆该元素?
这似乎很可笑,但这可能是你最好的选择 - 使。没有参数的css()
得到所有这些东西设置的对象。
jQuery.fn。 css =(function(css2){
return function(){
if(arguments.length){return css2.apply(this,arguments);}
var attr = family-','font-size','font-weight','font-style','color',
'text-transform'
'background-image','background-repeat','background-color',
'line-height','text-align' ,'background','background','background','background','background-attachment' margin-top','margin-right','margin-bottom','margin-left',
'padding-top','padding-right','padding-bottom','padding-left' ,
'border-top-width','border-right-width','border-bottom-width',
'border-left-width','border-top-color' border-right-color',
'border-bottom-color','border-left-color','border-top-style'底部样式','边界左侧样式','位置',
'显示','可见性','z-索引','溢出-X','溢出Y' space',
'clip','float','clear','cursor','list-style-image','list-style-position',
'list-style-position' ,'marker-offset'];
var len = attr.length,obj = {};
for(var i = 0; i obj [attr [i]] = css2.call(this,attr [i]);
}
return obj;
};
})(jQuery.fn.css);注意,这不会捕获所有可能的CSS属性,特别是CSS3的新属性。以下是所有标准CSS和稳定CSS3属性的列表,这里是以连字符为前缀的供应商特定属性(例如 -moz-border-start
)。如果你真的想要所有的人,你可以从那里收集他们。
I need to get list of elements all css attributes. How can I do that ?
解决方案 Copying the source from SO1004475 - jQuery CSS plugin that returns computed style of element to pseudo clone that element? - Please follow link and upvote there if you find it useful.
It seems ridiculous, but this is probably your best option - makes .css()
with no arguments get an object with all this stuff set.
jQuery.fn.css = (function(css2) {
return function() {
if (arguments.length) { return css2.apply(this, arguments); }
var attr = ['font-family','font-size','font-weight','font-style','color',
'text-transform','text-decoration','letter-spacing','word-spacing',
'line-height','text-align','vertical-align','direction','background-color',
'background-image','background-repeat','background-position',
'background-attachment','opacity','width','height','top','right','bottom',
'left','margin-top','margin-right','margin-bottom','margin-left',
'padding-top','padding-right','padding-bottom','padding-left',
'border-top-width','border-right-width','border-bottom-width',
'border-left-width','border-top-color','border-right-color',
'border-bottom-color','border-left-color','border-top-style',
'border-right-style','border-bottom-style','border-left-style','position',
'display','visibility','z-index','overflow-x','overflow-y','white-space',
'clip','float','clear','cursor','list-style-image','list-style-position',
'list-style-type','marker-offset'];
var len = attr.length, obj = {};
for (var i = 0; i < len; i++) {
obj[attr[i]] = css2.call(this, attr[i]);
}
return obj;
};
})(jQuery.fn.css);
Note that this doesn't capture all possible CSS properties, particularly new ones for CSS3. Here is a list of all standard CSS and stable CSS3 properties, and here's one of hyphen-prefixed vendor-specific properties (such as -moz-border-start
). If you really want all of them, you can glean them from there.
这篇关于我如何得到所有的元素CSS属性的列表与jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!