您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JavaScript实现开关效果的代码分享

2025/12/23 7:00:18发布19次查看
本文给大家分享一段简单的代码基于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实现开关效果的代码分享的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product