<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head>
<body> <button id="btn">开</button> </body> <script>
var btnE = document.getElementById('btn'),
text;
btnE.addEventListener('click', function () {
text = btnE.innerText;
btnE.innerText = text === "开" ? "关" : "开";
text === "开" ? document.body.style.backgroundColor = "black" : document.body.style.backgroundColor = "white";
});
</script>
</html>