나는이 카운트 다운 타이머에 대해 한동안 고심하고있다. 나는 많은 진전을 이루었지만 어떤 이유로 분과 초가 0 일 때 시간을 줄이지 않습니다. 왜 이런거야?
암호:
<?php
$timeTo = strtotime(gmdate("12:24:00")).'<br />';
$timeNow = strtotime('now').'<br />';
$differenceInSeconds = $timeTo - $timeNow;
?>
<script type="text/javascript">
var s= "<?php Print($differenceInSeconds);?>";
var h= Math.floor(s/3600);
s-= h*3600;
var m= Math.floor(s/60);
s -= m*60;
var counter=setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
s=s-1;
if(s == 0 ){
m=m-1;
s=59;
if(s == 0 && m == 0){
h=h-1;
s=59;
m=59;
if(s == 0 && m == 0 && h == 0){
// reset the counter
//return;
}
}
}
//Do code for showing the number of seconds here
document.getElementById("timer").innerHTML=h+'hrs '+m+'min '+s+'secs ';//(h <= 0 ? ' ' : h+"hr ")+(m <= 0 ? ' ' : m+"min ")+(s < 10 ? '0'+s+'secs ' : s+"secs "); // watch for spelling
}
</script>
<span id="timer"></span>
여기 JSFiddle
먼저 확인한 s == 0
다음 반대 순서가 아닌 감소합니다.
s=s-1; // s will be -1
if(s == 0 ){
그러나
if (s == 0) {
// logic here
} else {
s = s - 1;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다