-1
信息我想使用JavaScript 没有jQuery的或任何其他JS库从内部/外部styleshet返回风格没有jQuery的告诉从外部CSS文件或内部样式表
<style type="text/css"> <!-- From internal/external stylesheet -->
div{
height:30px;
width:45px;
background-color:#4445C7;
}
</style>
<div id="counter-element" style="width:3px;height:10px;"></div>
<div id="example"></div>
<script type="text/javascript">
function getStyle(elem,prop){
return elem.style[prop];
}
alert(getStyle(document.getElementById("counter-element"),"origional-background-color"); //I know this won't work. I'm just putting it in for an example
alert(getStyle(document.getElementById("example"),"background-color");
</script>
如果你想知道申请什么风格从直接应用的样式或样式表样式到给定的对象,然后您可以按照[这里](https://developer.mozilla.org/en-US/docs/Web/API/Window)所述使用'getComputedStyle()'。 getComputedStyle)在MDN中。 – jfriend00 2014-10-18 22:16:42