javascript修改css样式表

//创建
var sheet=document.createElement('style');
document.bodt.appendChild(sheet);
sheet.styleSheet.cssText="div{border:2px solid black; background-color:blue;}";
//删除
var beRemoved=document.getElementById('styleSheetId');
var sheetParent=beRemoved.parentNode;//获取要删除样式的父类
sheetParent.removeChild(beRemoved);//用removeChild()从父类中删除样式
//用title区分内部和外部样式表
function getStyleSheet(unique_title){
for(var i=0;i<document.styleSheets.length;i++){
var sheet=document.styleSheets[i];
if(sheet.title==unique_title){
return sheet;
}
}
}
//通过disabled属性禁用CSS
function disableSheet(){
document.getElementById('disable_example').disabled=true;
}
function enableSheet(){
document.getElementById('disable_example').disabled=false;
}

365个夜晚,我希望做到两天更一篇博客。加油,小白!
原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/11169633.html