---
title: "javascript获取元素CSS样式值"
author: "deng131"
date: "2011-06-18T14:36:13Z"
tags: []
categories: ["Web前端"]
slug: "javascript-css"
draft: false
lastmod: "2011-06-18T14:37:44Z"
id: 1097409
url: "https://thinking80s.iteye.com/blog/1097409"
---

IE:
element.currentStyle

currentStyle 对象返回了元素上的样式表，但是 style 对象只返回通过 style 标签属性应用到元素的内嵌样式。因此，通过 currentStyle 对象获取的样式值可能与通过 style 对象获取的样式值不同。例如，如果段落的 color 属性值通过链接或嵌入样式表设置为红色( red )，而不是内嵌的话，对象.currentStyle.color 将返回正确的颜色，而对象 style.color 不能返回值。但是，如果用户指定了 <P style="color:’red’">，currentStyle 和 style 对象都将返回值 red。
currentStyle 对象反映了样式表中的样式优先顺序。

在 HTML 中此顺序为：
内嵌样式 －》样式表规则－》HTML 标签属性－》HTML 标签的内部定义

W3C:
window.getComputedStyle(element,pseudoElt)
element 必选，HTML元素
pseudoElt 必选，获取该元素的伪类样式

参考：
<http://www.quirksmode.org/dom/w3c_css.html>
<http://foxling.org/category/js-ajax-dom/page/3/>