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

2017-09-13  本文已影响0人  f675b1a02698

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);

上一篇 下一篇

猜你喜欢

热点阅读