Home >Web Front-end >JS Tutorial >js light switch small application

js light switch small application

一个新手
一个新手Original
2017-09-08 11:20:351853browse


The application of judgment in js [switch light]


<!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>


The above is the detailed content of js light switch small application. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn