当我加载页面时,无论我做什么都不会出现时钟。我创建了两个按钮。如果我删除引用stopTime()
包含的功能的按钮,clearTimeout(t);
则会出现我的时钟。如果我把按钮放回去,我的时钟将无法工作。
<body onload="getTime()">
<script>
var t;
function getTime()
{
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
hour = checkTime(hour);
minute = checkTime(minute);
second = checkTime(second);
var actualtime = hour + ":" + minute + ":" + second;
document.getElementById("time").innerHTML = actualtime;
t = setTimeout(function(){getTime()},1000);
}
function checkTime(i)
{
if ( i < 10 )
i = "0" + i;
return i;
}
function stopTime();
{
clearTimeout(t);
}
</script>
</body>
</html>
提前致谢!