JS练习开关灯

<style type="text/css">
html,body{
margin: 0;
padding: 0;;
cursor: pointer;
100%;
height: 100%;
}
</style>


<body id="ids">
<script type="text/javascript">
console.log("开始");
var did =document.getElementById("ids");
did.onclick = function(){
console.log("sad");
var bg =this.style.backgroundColor;

switch (bg){
case "white" :
this.style.backgroundColor = "blue";
break;
case "blue" :
this.style.backgroundColor = "red";
break;
case "red" :
this.style.backgroundColor ="yellow";
break;
case "yellow" :
this.style.backgroundColor = "black";
break;
default: this.style.backgroundColor ="white";
}
}
</script>
</body>
原文地址:https://www.cnblogs.com/zzzzzzzsy/p/6565200.html