Home >Web Front-end >JS Tutorial >js dynamically modify css files using the cssRule_javascript technique
_.find(document.styleSheets[4].cssRules,function(cssRule){ if(cssRule.selectorText && cssRule.selectorText.indexOf(".navbar-fixed-top2")>-1){ cssRule.style.position=""; cssRule.style.top = "0px"; } if(cssRule.selectorText && cssRule.selectorText.indexOf("#pageIndi_content, #page1_l1_content, #page_appList") >-1){ cssRule.style.padding = "0px"; } if(cssRule.selectorText && cssRule.selectorText.indexOf("#page1_index_content") >-1){ cssRule.style.padding = "0px"; } });
The underscore used for looping cannot be used directly when using cssRule, otherwise it will not take effect
cssRule.style=" left: 0;position:'';right: 0; top: 0px;z-index: 1031;";
can only be used
cssRule.style.padding = "0px";