<!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開關燈小應用的詳細內容。更多資訊請關注PHP中文網其他相關文章!