我想在答案框中的值为119时暂停计时器 当值为119时,我无法暂停计时器或clearInterval,计时器不会暂停。
<body onload="document.getElementById('box1').focus, startTimer(), pause()">
<input onkeyup="sum(),secret()" id="box1" autofocus/><br><br>
<input onkeyup="sum(),secret()" id="box2"/><br><br>
<input id="ans" disabled/>
<p id="secret" style="display: none;">
Time paused
</p>
<script>
function secret() {
if(document.getElementById('ans').value == "119") {
document.getElementById('secret').style.display = "block";
}
else {
document.getElementById('secret').style.display = "none";
}
}
function sum() {
var x = document.getElementById('box1').value;
var y = document.getElementById('box2').value;
var a = +x + +y;
document.getElementById('ans').value = a;
}
function startTimer() {
var fiveMinutes = 30,
display = document.getElementById("time"),
mins, seconds;
var tt = setInterval(function() {
mins = parseInt(fiveMinutes / 60)
seconds = parseInt(fiveMinutes % 60);
seconds = seconds < 10 ? "0" + seconds : seconds;
display.innerHTML = mins + ":" + seconds;
fiveMinutes--;
if (fiveMinutes < 0) {
document.getElementById('timeup').style.display = "block";
clearInterval(tt);
}
}, 1000);
}
function pause() {
setInterval(pau, 10);
}
function pau() {
if(document.getElementById('secret').style.display == "block") {
}
}
</script>
<br>
<br>
<div onchange="pause()" id="time"></div>
<p id="timeup" style="display: none;">Time up </p>
</body>