我有计时器倒计时的javascript代码。当前输出是,第二个数字从60减少到0,但是当秒数字达到0时,分钟数字不会减少。我在下面添加了一个jsfiddle,请帮帮我。 jsFiddle:https://jsfiddle.net/jyv3gLup/
我的javaScript代码添加在下面,
function getDifferenceTime(){
var deadline= Date.parse(new Date("2016-11-1T05:00:00"));
var difval= deadline- Date.parse(new Date());
var days= Math.floor(difval/(1000*60*60*24));
var hours= Math.floor( (difval/(1000*60*60))%24);
var minutes= Math.floor( (difval/(1000/60))%60);
var seconds= Math.floor( (difval/1000)%60);
document.getElementById("tes").innerHTML= days + "Days and " +hours + "hours and " + minutes + " Minutes and" + seconds;
}
getDifferenceTime();
setInterval(getDifferenceTime, 1000);
答案 0 :(得分:0)
function getDifferenceTime(){
var deadline= Date.parse(new Date("2016-11-1T05:00:00"));
var diff_val= deadline- Date.parse(new Date());
var days= Math.floor(diff_val/(1000*60*60*24));
var hours= Math.floor((diff_val/(1000*60*60))%24);
var minutes= Math.floor((diff_val/(1000*60))%60);
var seconds= Math.floor((diff_val/1000)%60); document.getElementById("date_test").innerHTML= days + "Days and " +hours + "hours and " + minutes + " Minutes and " + seconds;
var clear_value = document.getElementById("date_test").innerHTML;
if( (days==0) && (hours==0) && (minutes==0) && (seconds==0) ){
clearInterval(clear_value); // clears your timer
}
}// function close
getDifferenceTime();
setInterval(getDifferenceTime, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="date_test"></div>
这是JSFiddle
答案 1 :(得分:-1)
你有这个:Math.floor((difval/(1000/60)%60);
它应该是Math.floor((difval/(1000*60)%60);