When the whole world is about to rain, let's make it clear in our heart together

热爱前端开发,专注于前端

DoM样式方法

getPropertyValue(propertyName (如“background-color")) --返回css特性propertyName的字符串值。
removeProperty(propertyName )---从css中删除propertyName。
setProperty(propertyName,value,priority)---最后一个参数为空字符或者important。

访问样式表css规则

注意:使用style对象可以方便获取某个有style特性元素的样式的css样式,但它无法表示由css规则或者在style特性外部定义的类定义的元素的样式。
解决方案:
DOM为每一个样式表指定了一个cssRules的集合,它包含所有定义在样式表中的css规则,如下:
var orules=document.styleSheets[0].cssRules||document.styleSheets[0].rules;(检测不同浏览器,IE支持rules)

获取IE行间样式为或者类定义样式:obj.currentStyle.backgroundColor  
获取DOM行间样式或者类定义样式为:document.defaultView.getComputedStyle(obj,null).backgroundColor---最终显示的是RGB的样式
posted @ 2016-05-22 20:00  婷风  阅读(127)  评论(0)    收藏  举报