获取CSS类的样式 [英] Get styles of a CSS class

查看:90
本文介绍了获取CSS类的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取元素的样式并将其写出.问题是,样式是通过多个类给出的.有没有办法让我确切地了解哪些样式正在影响元素?

好的,我认为这个问题很容易解释,但是在这里:

I need to get the style of an element and write it out. The problem is, the styles are given though multiple classes. Is there a way for me to see exactly what styles are influencing an element?

Ok, I think the question is pretty self explanatory, but here:

<div id="myDiv" class="divClass">
<label class="labelClass">Hello World</label>
</div>



假设 divClass 具有"width:250px",而 labelClass 具有"color:#e3e3e3".我需要通过JavaScript函数获得这些样式.



Lets say that the divClass has "width:250px", and the labelClass has "color:#e3e3e3". I need to get those styles through a JavaScript function.

推荐答案

firebug [ ^ ]将帮助您

使用javascript
获取元素的渲染样式 [ ^ ]
firebug[^] will help you

Using javascript
Get the rendered style of an element[^]


感谢您的提问.



Thanks for your question.



var omyDiv = document.getElementById('myDiv');
var class= omyDiv.style.className;



谢谢,
马蒙



Thanks,
Mamun


document.getElementById(''myDiv'').className



这将返回您在控件上应用的类.



This will return you the applied class on the control.


这篇关于获取CSS类的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆