动态修改css 规则

页面引用了两个样式表:

 <link href="css/mui.min.css" rel="stylesheet" />

<link href="css/menu.css" rel="stylesheet" /> 

 //根据样式引用顺序索引获取样式表对象,此处获取结果为menu.css样式对象

var menuCss = document.styleSheets[1]; var rule;                for(var i=0; i<menuCss.cssRules.length; i++){                     rule = menuCss.cssRules[i]                     if(rule.type == CSSRule.KEYFRAMES_RULE 

|| rule.type == CSSRule.WEBKIT_KEYFRAMES_RULE
                         || rule.type == CSSRule.MOZ_KEYFRAMES_RULE ) //&& i==0
                     {
                         console.log(rule.cssText);
                         break;
                     }
                }

for(var item in rule){
console.log(item);
}
输出样式规则对象属性
cssRules at new_touchMove.html:204
name at new_touchMove.html:204
parentRule at new_touchMove.html:204
parentStyleSheet at new_touchMove.html:204
cssText at new_touchMove.html:204
type at new_touchMove.html:204
insertRule at new_touchMove.html:204
deleteRule at new_touchMove.html:204
findRule at new_touchMove.html:204
UNKNOWN_RULE at new_touchMove.html:204
STYLE_RULE at new_touchMove.html:204
CHARSET_RULE at new_touchMove.html:204
IMPORT_RULE at new_touchMove.html:204
MEDIA_RULE at new_touchMove.html:204
FONT_FACE_RULE at new_touchMove.html:204
PAGE_RULE at new_touchMove.html:204
WEBKIT_KEYFRAMES_RULE at new_touchMove.html:204
WEBKIT_KEYFRAME_RULE at new_touchMove.html:204
SUPPORTS_RULE at new_touchMove.html:204
WEBKIT_FILTER_RULE at new_touchMove.html:204
HOST_RULE at new_touchMove.html:204

猜你喜欢

转载自www.cnblogs.com/wgx0428/p/9199323.html