2013-07-04 6 views
0

JS로 매우 기본적인 것을 수행하려고합니다. 숨겨진 태그에서 남은 초의 양을 가져온 다음이 태그를 파싱하는 카운트 다운이 있습니다. 함수의 끝에서 span 태그의 초 단위로 간격 타이머를 제거하려고합니다. 이 순간 내가 행한 :자바 스크립트 기본 수학

parseInt($(this).find("#sqbTimestamp").text()) - 3; 

나는 다음의 setTimeout을 사용 (기능, 2) (그것을 처리하는 초 여유를 줄) 그것을 2 초마다 실행합니다. 그러나 위의 계산에서 콘솔 로그로 출력 된 숫자는 함수를 실행할 때마다 동일합니다. 스팬 컨테이너 초

function countdownProcedure(){ 
     var interval = 10000; 
     var i = 0; 
     var seconds = null; 
     console.log(C++) 
     $(".rfqTbl tr").each(function(){ 
       if(i > 0){ 
         seconds = $(this).find("#sqbTimestamp").text(); 
         var tsInt = parseInt($(this).find("#sqbTimestamp").text()); 

         var days = Math.floor(seconds/(60*60*24)); 
         seconds -= days * 60 * 60 * 24; 
         var hours = Math.floor(seconds/(60*60)); 
         seconds -= hours * 60 * 60; 
         var minutes = Math.floor(seconds/60); 
         seconds -= minutes * 60; 

         //$(this).find("#sqlTimestamp").text(newTS); 
         console.log(tsInt - 3); 

         if(days < 1){ days=""; } 
         $(this).find("#countDown").html(days + "<pre> Days</pre> " + hours + "<pre>:</pre>" + minutes + "<pre>:</pre>" + seconds); 
         $(this).find("#countDown").append(i + " - " + seconds); 
         if(days > 1){ 
           $(this).find("#countDown").css({ 
             'color':'#2A7F15', 
             'font-weight':'bold' 
           }); 
         }; 
         if(days < 1){ 
           $(this).find('#countDown').css('color','red'); 
           $(this).find('#countDown pre:nth-of-type(1)').css('display','none'); 
         } 
         if(seconds < 10){ $(this).find("#countDown").append("&nbsp;"); }; 
         if(minutes < 60){ interval = 1000; }; 
       } 
       i++; 
     }); 
     setTimeout(countdownProcedure,interval); 
}; 
+0

'setTimeout'은 초가 아니라 * 밀리 초 *입니다. – Bergi

+1

#sqbTimestamp 텍스트를 업데이트하지 않으므로 log (tsInt - 3)는 항상 동일합니다. – elnabo

+0

"* 함수 끝에서 span 태그에서 초 단위로 간격 타이머를 제거하고 싶습니다. *"- 아무데도 보이지 않습니까? – Bergi

답변

0

$(this).find("#sqbTimestamp").html(tsInt + 1); 코드 변화량 :

여기에 전체 코드입니다.

//Run countdown proecudure 
countdownProcedure(); 

var runNo = 0; 
function countdownProcedure(){ 
     var interval = 10000; 
     var i = 0; 
     var seconds = null; 
     runNo++; 
     $(".rfqTbl tr").each(function(){ 
       if(i > 0){ 
         seconds = $(this).find("#sqbTimestamp").text(); 
         var tsInt = parseInt($(this).find("#sqbTimestamp").text()); 
         $(this).find("#sqbTimestamp").html(tsInt + 1); 

         var days = Math.floor(seconds/(60*60*24)); 
         seconds -= days * 60 * 60 * 24; 
         var hours = Math.floor(seconds/(60*60)); 
         seconds -= hours * 60 * 60; 
         var minutes = Math.floor(seconds/60); 
         seconds -= minutes * 60; 

         $(this).find("#sqlTimestamp").text(tsInt - 3); 
         console.log(tsInt - 3); 

         if(days < 1){ days=""; } 
        $(this).find("#countDown").html(days + "<pre> Days</pre> " + hours + "<pre>:</pre>" + minutes + "<pre>:</pre>" + seconds + "<pre>Run Number: " + runNo + "</pre>"); 

         if(days > 1){ 
           $(this).find("#countDown").css({ 
             'color':'#2A7F15', 
             'font-weight':'bold' 
           }); 
         }; 
         if(days < 1){ 
           $(this).find('#countDown').css('color','red'); 
           $(this).find('#countDown pre:nth-of-type(1)').css('display','none'); 
         } 
         if(seconds < 10){ $(this).find("#countDown").append("&nbsp;"); }; 
         if(minutes < 60){ interval = 1000; }; 
       } 
       i++; 
     }); 
     setTimeout(countdownProcedure,interval); 
}; 
+0

나는 피들 http://jsfiddle.net/RpUv3/2/에 버전을 넣었습니다. 피드백을 보내 주시면 감사하겠습니다 - 함수가 계속 실행되지만 초 수는 동일하게 유지되고 감소하지 않음을 알 수 있습니다. 많은 감사합니다 –

+0

나는 내 대답을 업데이 트했습니다. – mvb13