js的style属性
首先css样式表有三种样式,
一、内联样式
在HTML标签用style属性设置,如 :
<p style="color:#f90;">这是内联样式</p>
二、嵌入样式
通过<head>标签内通过<style>标签设置。如:
<style type="text/css">
/*这是嵌入样式*/
.stuff{color:#f90}
</style>
三、外部样式
通过<link>标签设置。如:
<link rel="stylesheet" href="path/style.css" type="text/css">
而在javascript中,获取这三种样式表的方法是有限制的,style只能获取元素的内联样式,
嵌入样式和外部样式使用style是获取不到的,javascript提供了另外的获取方式,嵌入样式和外部样式可以通过currentStyle(IE浏览器)、getComputedStyle(Firefox、opera、safari、chrome浏览器)的方式获取。
使用方法分别是window.currentStyle["attr']和window.getComputedStyle(ob, pseudoElt)["attr']。