1 回答

TA贡献1848条经验 获得超6个赞
使用clearInterval函数https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval
WindowOrWorkerGlobalScope mixin 的 clearInterval() 方法取消了之前通过调用 setInterval() 建立的定时重复操作。
var interval = setInterval(function(){
var d = new Date()
var h = d.getHours()
var m = d.getMinutes()
var s = d.getSeconds()
h = (h < 10) ? ("0" + h) : h;
m = (m < 10) ? ("0" + m) : m;
s = (s < 10) ? ("0" + s) : s;
document.getElementById("time").value = h +":"+m+":"+s
}, 1000)
// this will cancel the interval when you want it to
clearInterval(interval);
添加回答
举报