date()에 연결된 시계를 만들었습니다. getHours/minutes/Seconds 쇼 이미지는 다른 클래스에 포함되어 있습니다.변경 클래스의 스위치보다 더 나은 솔루션 이름
이제 이미지를 바꾸고 싶을 때마다 매분 2 시간마다 스위치를 썼습니다. Google 검색 엔진보다 코드가 더 많습니다. 그래서 더 간단한 해결책이 있는지 궁금합니다.
이것은 시간 스위치 의 일부 코드이므로 분 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 = "시계 -digit-"+ 숫자 [t [0]]; hours.appendChild (hour2) .className = "시계 -digit-"+ 숫자 [t [1]] 등 – Offbeatmammal