首頁 > web前端 > js教程 > 主體

js開關燈小應用

一个新手
發布: 2017-09-08 11:20:35
原創
1754 人瀏覽過


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>
登入後複製


以上是js開關燈小應用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!