1.用document.styleSheets获得通过style标签和link标签加入的样式 |
返回类型 |
var styleSheetList=document.styleSheets; |
//object StyleSheetList |
var styleSheet=document.styleSheets[i]; |
//object CSSStyleSheet |
var cssRuleList=document.styleSheets[i].cssRules; |
//object CSSRuleList |
var cssRule=document.styleSheets[i].cssRules[j]; |
//object CSSStyleRule |
var style=document.styleSheets[i].cssRules[j].style; |
//FF:object CSS2Properties; //IE:object MSStyleCSSProperties |
style.backgroundColor='pink'; |
//JS可用这种方式设置样式 |
2.用HTMLStyleElement.sheet获得style标签链入的样式 |
返回类型 |
var oHTMLStyleElement=document.getElementsByTagName('style')[0]; |
//object HTMLStyleElement |
var styleSheet=oHTMLStyleElement.sheet; |
//object CSSStyleSheet |
3.用HTMLLinkElement.sheet获得link标签链入的样式 |
返回类型 |
var oHTMLLinkElement=document.getElementsByTagName('link')[0]; |
//object HTMLLinkElement |
var styleSheet=oHTMLStyleElement.sheet; |
//object CSSStyleSheet |