js根据时间自动更换背景代码

var d = new Date();

//显示当前时间的小时数,测试用的,可以删除document.write( d.getHours() );

var time=d.getHours();

if (time==1){document.getElementById("a").style.backgroundColor="#0066CC";}

if (time==2){document.getElementById("a").style.backgroundColor="#0072E3";}

if (time==3){document.getElementById("a").style.backgroundColor="#0080FF";}

if (time==4){document.getElementById("a").style.backgroundColor="#2894FF";}

if (time==5){document.getElementById("a").style.backgroundColor="#46A3FF";}

if (time==6){document.getElementById("a").style.backgroundColor="#66B3FF";}

if (time==7){document.getElementById("a").style.backgroundColor="#84C1FF";}

if (time==8){document.getElementById("a").style.backgroundColor="#97CBFF";}

if (time==9){document.getElementById("a").style.backgroundColor="#ACD6FF";}

if (time==10){document.getElementById("a").style.backgroundColor="#C4E1FF";}

if (time==11){document.getElementById("a").style.backgroundColor="#D2E9FF";}

if (time==12){document.getElementById("a").style.backgroundColor="#ECF5FF";}

if (time==13){document.getElementById("a").style.backgroundColor="#D2E9FF";}

if (time==14){document.getElementById("a").style.backgroundColor="#C4E1FF";}

if (time==15){document.getElementById("a").style.backgroundColor="#ACD6FF";}

if (time==16){document.getElementById("a").style.backgroundColor="#97CBFF";}

if (time==17){document.getElementById("a").style.backgroundColor="#84C1FF";}

if (time==18){document.getElementById("a").style.backgroundColor="#66B3FF";}

if (time==19){document.getElementById("a").style.backgroundColor="#46A3FF";}

if (time==20){document.getElementById("a").style.backgroundColor="#2894FF";}

if (time==21){document.getElementById("a").style.backgroundColor="#0080FF";}

if (time==22){document.getElementById("a").style.backgroundColor="#0072E3";}

if (time==23){document.getElementById("a").style.backgroundColor="#0066CC";}

alert(time);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容