2011-09-16 3 views
1

메신저는 js의 특정 날짜에 카운트 다운 시계를 쓰려고합니다. 내가 페이지에 출력하지만 innerhtml을 사용하여 div에 쓰는 것 같다면 다음과 같은 작동합니까?자바 스크립트 카운트 다운 시계

아무도 내가 잘못 가고있는 것을 볼 수 있습니까?

today = new Date(); 
expo = new Date("February 05, 2012"); 
msPerDay = 24 * 60 * 60 * 1000 ; 
timeLeft = (expo.getTime() - today.getTime()); 
e_daysLeft = timeLeft/msPerDay; 
daysLeft = Math.floor(e_daysLeft); 
document.getElementById('cdown').innerHTML = document.write(daysLeft); 

답변

7
document.getElementById('cdown').innerHTML = daysLeft 

2

이 문서에 daysLeft 아닌 div 쓰기 것, document.write(daysLeft)를 사용하지 마십시오 document.write를 당신은 필요 없어! 그냥 daysLeft을 설정

document.getElementById('cdown').innerHTML = daysLeft; 
2

을이 라인에 :

document.getElementById('cdown').innerHTML = document.write(daysLeft); 

document.write(를 제거합니다. 요소의 내용을 설정하는 경우에는 문서에 쓸 필요가 없습니다.

고정 코드 :

today = new Date(); 
expo = new Date("February 05, 2012"); 
msPerDay = 24 * 60 * 60 * 1000 ; 
timeLeft = (expo.getTime() - today.getTime()); 
e_daysLeft = timeLeft/msPerDay; 
daysLeft = Math.floor(e_daysLeft); 
document.getElementById('cdown').innerHTML = daysLeft;