如何使用Javascript获取元素的不透明度? [英] How do I get the opacity of an element using Javascript?
本文介绍了如何使用Javascript获取元素的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有:
#em {
opacity:0.5;
}
如何获得 #em
的不透明度使用 javascript
? :D
How do I get #em
's opacity using javascript
? :D
我遇到以下问题(不返回任何内容):
I've got troubles with the following (it returns nothing):
return document.getElementById("em").style.opacity;
推荐答案
在样式表中设置CSS值不一样如通过 style
属性设置它。您需要查看 getComputedStyle
方法获得这个(以及 currentStyle
for old IE)。
Setting a CSS value in a stylesheet is not the same as setting it through the style
property. You need to look at the getComputedStyle
method to obtain this (and also currentStyle
for older IE).
这篇关于如何使用Javascript获取元素的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文