我已创建一个时钟,连接到日期()。getHours/minutes/Seconds 显示的图像嵌入在不同的类。更好的解决方案比开关更改classNames
现在,当我想改变图像,我写了一个开关,每隔一分钟和几小时.. 这可能比谷歌引擎更多的代码。所以我想知道是否有更简单的解决方案。
这是小时开关 的某些代码,所以当15分钟到达时钟时,它将className更改为1和5。
switch(h){
case 15:
x = hours.appendChild(hour1).className = "clock-digit-one";
x = hours.appendChild(hour2).className = "clock-digit-five";
break
case 16:
x = hours.appendChild(hour1).className = "clock-digit-one";
x = hours.appendChild(hour2).className = "clock-digit-six";
break
default:
x = hours.appendChild(hour1).className = "clock-digit-zero";
x = hours.appendChild(hour2).className = "clock-digit-zero";
}
我已经创建了一个显示更多代码的jsFiddle。 任何提示都会很棒。 http://jsfiddle.net/Xk49c/2/
感谢
我会花时间,转换为6个位置(h,h,m,m,s,s)的数组“t”,然后引用一个数组[“zero”,“one ...”nine“],然后使用小时.appendChild(hour1).className =“clock-digit-”+ digit [t [0]]; hours.appendChild(hour2).className =“clock-digit-”+ digit [t [1]];等 – Offbeatmammal 2013-02-08 16:34:48