最简单的主题解决方案

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        .wrap{
            width: 100vw;
            height: 100vh;
        }
        [class='theme_white']>.wrap{
            background-color: lightgray;
        }
        [class='theme_black']>.wrap{
            background-color: black;
        }
    </style>
</head>
<body class="theme_white">
    <div class="wrap">
        <select id="select">
            <option value='theme_white'>白</option>
            <option value='theme_black'>黑</option>
        </select>    
    </div>
</body>
<script type="text/javascript">
    let dom = document.getElementById('select');
    let body = document.getElementsByTagName('body')[0];
    dom.onchange = function(){
        body.className = dom.value;
    }
</script>
</html>
    原文作者:LeeTse
    原文地址: https://segmentfault.com/a/1190000018740378
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞