javascript学习指南_JavaScript实现开关效果简介

更新时间:2021-08-16    来源:网页配色    手机版     字体:

【www.bbyears.com--网页配色】

使用JavaScript实现开关效果也是很多人会遇到的操作,这次文章就给大家简单的介绍下方法,感兴趣的一起来看看。




 
 开关灯
 


<script type="text/javascript">
 var oBody = document.getElementById("bodyEle");
 oBody.onclick = function () {
  var bg = this.style.backgroundColor;
  switch (bg) {
   case "white":
    this.style.backgroundColor = "red";
    break;
   case "red":
    this.style.backgroundColor = "black";
    break;
   default:
    this.style.backgroundColor = "white";
  }

 }
</script>

本文来源:http://www.bbyears.com/wangyezhizuo/136291.html

猜你感兴趣