我有一个秒表,效果很好,但在 60 秒后的秒值中,我需要计时器转到零,分钟到 1,并且以同样的方式,每 60 秒分钟应该改变
/* Stopwatch */
starttime(){
console.log("timer started");
if( this.running == 0){
this.running = 1;
this.adder()
}else{
this.running = 0;
}
}
reset(){
console.log("timer reset");
this.running = 0;
this.time = 0;
this.total = 0;
this.Sec = 0;
}
adder(){
console.log("timer incrementor");
if(this.running == 1){
setTimeout(()=>{
this.time++;
var mins = Math.floor(this.time/10/60);
var sec = Math.floor(this.time / 10 );
var tens = this.time/10;
this.total = mins + ':' + sec;
console.log(this.total) ;
this.Sec = sec;
this.adder()
},10)
}
}
但是这里时间发生了变化,秒被累加起来,当它达到 60 时它不会变为零,它会移动到 61,62,63.... 120 秒后的采样时间是 0:2:120,我需要什么是 0:2:0(小时:秒:分钟)
修改“var sec = Math.floor(this.time/10)%60;”后工作正常并将设置超时时间更改为
this.adder()
},100)
最佳答案
关于javascript - 创建秒表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42665301/