我正在用JS实现一个模拟和数字手表。通过几个教程就可以工作了,但是我如何停止时钟并更改时间呢?以下是数字一的代码:
function updateClock() {
var currentTime = new Date();
var gtmStatus = 'AM';
var hours = currentTime.getHours();
if (hours > 12){
hours = hours-12;
gtmStatus = 'PM';
}
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var degree_seconds = -90 + (seconds * 6);
var degree_minute = -90 + (minutes * 6);
var degree_hour = -90 + (hours * 30);
degree_hour = degree_hour + (0.5 * minutes);
$('#time').html(hours + ':' + minutes + ':' + seconds + ' ' + gtmStatus);
setInterval(updateClock, 1000);
updateClock();
}发布于 2015-02-02 01:09:34
setInterval(...)返回一个可以提供给clearInterval(handle)的句柄/标识符。
换句话说,如果您想暂停时钟,则需要使用上次调用setInterval(...)时获得的句柄来调用clearInterval(...)。然后,您可以启动时钟,再次调用setInterval(...)。
发布于 2015-02-02 01:11:23
function getThatThereTime () {
return $('#time').val();
}https://stackoverflow.com/questions/28265290
复制相似问题