JS编程中开关灯效果如何实现
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>开关灯</title>
<style type="text/css">
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
cursor: pointer;
background-color: white;
}
</style>
</head>
<body id="bodyEle">
<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>
</body>
</html>
总结
以上关于JS编程中开关灯效果如何实现的详细内容,不知道各位朋友都看明白了吗!想要了解更多不同类型的技术文章内容,来爱站技术频道网站吧!里面的文章应有尽有。
上一篇:js实现滚动条事件的实例代码
下一篇:JS编程中图片拖曳效果的实例代码
