获取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.