我有这个计时器代码,我试图让它在 0:0 停止,但它一直变成负数。任何解决此问题的想法都会有所帮助。
<html>
<head>
<script>
function startTimer(m,s)
{
document.getElementById('timer').innerHTML= m+":"+s;
if (s==0)
{
if (m == 0)
{
clearTimeout(t);
}
else if (m != 0)
{
m = m-1;
s = 60;
}
}
s = s-1;
t=setTimeout(function(){startTimer(m,s)},1000);
}
</script>
</head>
<body>
<button onClick = "startTimer(0,5)">Start</button>
<p id = "timer">00:00</p>
</body>
</html>