网络编程
位置:首页>> 网络编程>> JavaScript>> JavaScript实现开关等效果

JavaScript实现开关等效果

作者:ruirui_1996  发布时间:2024-04-25 13:13:55 

标签: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>

总结

以上所述是小编给大家介绍的JavaScript实现开关等效果网站的支持!

来源:http://blog.csdn.net/ruirui_1996/article/details/77892131

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com