<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <input type="button" value="关灯" id="btn">

  <script src="common.js"></script>
  <script>
    // 是否开灯  false 关灯状态  true 开灯状态
    var isOpen = true;
    my$('btn').onclick = function () {
      if (isOpen) {
        document.body.style.backgroundColor = 'black';
        this.value = '开灯';
        isOpen = false;
      } else {
        document.body.style.backgroundColor = 'white';
        this.value = '关灯';
        isOpen = true;
      }
    }
  </script>
  
</body>
</html>

 

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2021-11-30
  • 2021-12-09
猜你喜欢
  • 2021-11-07
  • 2022-03-12
  • 2022-01-17
  • 2021-12-09
  • 2021-12-09
  • 2021-12-23
  • 2022-12-23
相关资源
相似解决方案