简体   繁体   English

JS计时器未重置

[英]JS timer not resetting

Stopwatch resets, since clicking start again stop watch begins the counting at zero. 秒表将重置,因为再次单击开始秒表将使计数从零开始。 However, I would like to show zero out as well, similar to when the page is first refreshed. 但是,我也想显示零,类似于第一次刷新页面时。 Any ideas? 有任何想法吗?

https://jsfiddle.net/xmp5fq50/ https://jsfiddle.net/xmp5fq50/

var Stopwatch = function(elem, options) {
var timer = createTimer(),
startButton = createButton("Start", start, "start"),
stopButton = createButton("Stop", stop, "stop"),
resetButton = createButton("Reset", reset, "reset"),
offset,
clock,
interval;

If you are looking for it to go back to it's original state then you can simply remove render(0) from the reset function and replace with timer.innerHTML = ''; 如果您希望它恢复到原始状态,则只需从reset函数中删除render(0)并替换为timer.innerHTML = ''; This is possible since you are simply just needing to reset to starting state which would be an empty span. 这是可能的,因为您只需要重置为将为空跨度的起始状态。

If you wanted to reset to 0 and display that then you could do timer.innerHTML = '0.0'; 如果您想重置为0并显示,则可以执行timer.innerHTML = '0.0'; instead so that the span resets to a 0 state rather than hiding it. 而是将范围重置为0状态,而不是将其隐藏。

The resulting function would look something like: 结果函数如下所示:

function reset() {
    clock = 0;
    timer.innerHTML = '0.0';
}

I have adjusted the JSFiddle to show you. 我已经对JSFiddle进行了调整以向您展示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM