How to make changeable themes using CSS and JavaScript

后端 未结 6 1086
礼貌的吻别
礼貌的吻别 2020-11-28 22:42

I\'m pretty new to CSS and JavaScript and I was wondering if you could make a script that allows you to change what stylesheet the site uses.

Say: you had a green t

6条回答
  •  余生分开走
    2020-11-28 23:27

    If you want to switch back and forth between themes I recommend using the following for your javascript:

    var count = 0
    
    document.getElementById('trigger').onclick = function () {
        count = count + 1;
        if (count%2!=0){
          document.getElementById('default').href = 'changeTheme.css';
        } else {
          document.getElementById('default').href = 'main.css';
        }
    };
    

    Then using the markup mentioned earlier

提交回复
热议问题