Home > Web Front-end > JS Tutorial > body text

js light switch small application

一个新手
Release: 2017-09-08 11:20:35
Original
1753 people have browsed it


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>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!