0
每当我使用这种类型的JavaScript代码来欣赏元素的背景颜色时,它总是返回“”。如何从JavaScript的外部样式表派生元素样式?
<style><!--From external stylesheet-->
#divexample{
background-color:#4345C7;
}
</style>
<div id="divexample"></div>
<script type="text/javascript">
var bgColor=document.getElementById("divexample").style.backgroundColor;
alert(bgColor);
</script>
前加载你的风格JS? – Shomz 2014-09-28 00:44:49
检查[MSDN](https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle)。 – 2014-09-28 00:50:50