点击页面换颜色

我只想完成这件事,暂时保存一下代码,除了点小bug,一直不能设置为body,惨、

<!DOCTYPE html>
<html>
<head>
    <title>标题</title>
    <style type="text/css">
        html{background-color:white; height:100%;}
        body{background-color:#eee; height:100%; width:100%; }
        #aa{
            /*
            html{background-color:white; height:100%;}
            body{background-color:#eee; height:100%; width:100%; }
            */
            background-color:#eee;
        }
    </style>
    <script>
        window.onload = function(){
            var cnt=0;
            var obj=document.getElementById("aa");
            obj.onclick= function(){
    //            alert(1);
                   cnt++;
                   cnt=cnt-Math.floor(cnt/3)*3;
                   //alert(cnt);
                   if(cnt==0){
                        obj.style.backgroundColor="#eee";
                   }
                   else if(cnt==1) obj.style.backgroundColor="red";
                   else obj.style.backgroundColor="#000000";
            }
        }
    </script>
</head>
<body  id="aa">
    <!--<div id="aa" ></div>-->
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/lalalatianlalu/p/10169815.html