静态页面实现换肤功能(无cookie)

 

//1、将已存在的样式表css禁用掉

  for ( i = 0; i < document.styleSheets.length; i++ )
       {
        document.styleSheets[i].disabled = true;
       }

 

//2、添加新的样式表

       var selectedTheme = ...;//目标样式的路径

 

       var head = document.getElementsByTagName('HEAD').item(0);
       

       var ga = document.createElement('link');
       ga.rel = "stylesheet";
       ga.type = 'text/css'; 
       ga.href = selectedTheme ;
       head.appendChild(ga);

你可能感兴趣的:(WEB开发)