main.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var a=["0 1 2 4 5 6","2 5","0 2 3 4 6","0 2 3 5 6","1 2 3 5","0 1 3 5 6","0 1 3 4 5 6","0 2 5","0 1 2 3 4 5 6","0 1 2 3 5 6"];
  2. var b=["星期天","星期一","星期二","星期三","星期四","星期五"];
  3. window.onload=function () {
  4. showTime();
  5. setInterval(function(){
  6. showTime();
  7. },1000);
  8. }
  9. function showTime()
  10. {
  11. var time=new Date;
  12. var y=time.getFullYear();
  13. var M=time.getMonth();
  14. var d=time.getDate();
  15. var h=time.getHours();
  16. var m=time.getMinutes();
  17. var s=time.getSeconds();
  18. M=M+1;
  19. var str=y.toString()+"年"
  20. if(M<10)
  21. str=str+"0"+M.toString()+"月";
  22. else
  23. str=str+M.toString()+"月";
  24. if(d<10)
  25. str=str+"0"+d.toString()+"日";
  26. else
  27. str=str+d.toString()+"日";
  28. document.getElementById("date").getElementsByTagName("span")[0].innerHTML=str;
  29. document.getElementById("date").getElementsByTagName("span")[1].innerHTML=b[time.getDay()];
  30. modiflyNum(1,parseInt(h/10));
  31. modiflyNum(2,h%10);
  32. modiflyNum(3,parseInt(m/10));
  33. modiflyNum(4,m%10);
  34. modiflyNum(5,parseInt(s/10));
  35. modiflyNum(6,s%10);
  36. }
  37. function modiflyNum(id,value)
  38. {
  39. var elm=document.getElementById('time'+id.toString()).getElementsByTagName('li');
  40. var str=a[value];
  41. var cc=str.split(' ');
  42. for(var i=0;i<7;i++)
  43. {
  44. elm[i].getElementsByTagName('img')[0].src="images/back.png";
  45. }
  46. for(var i=0;i<cc.length;i++)
  47. {
  48. elm[parseInt(cc[i])].getElementsByTagName('img')[0].src="images/front.png";
  49. }
  50. }