是用setInterval每10ms调用一次倒计时方法,想让计时器在倒计时的时候点击停止能暂停,再点能继续
var FnSec=function(){
sec.innerHTML-=1;
if(sec.innerHTML<0){
sec.innerHTML="100";
time.innerHTML-=1;
}
if(time.innerHTML.length<2){
time.innerHTML="0"+time.innerHTML;
}
if(sec.innerHTML.length<2){
sec.innerHTML="0"+sec.innerHTML;
}
if (sec.innerHTML==0 && time.innerHTML==0) {
clearInterval(secInterValId);
var audio = document.getElementById("bgMusic");
audio.play();
window.alert("时间到!");
audio.pause();
start.innerHTML="开始";
inputDisable.style.display="none";
input.style.display="block";
resetDisable.style.display="block";
reset.style.display="none";
time.innerHTML="10";
sec.innerHTML="00";
}
}
var secInterValId=setInterval(FnSec,10);
start.innerHTML="停止";
刚学前端,今天刚学了间歇调用,小白捣鼓了一晚上都不行,没辙了,求大神帮忙看一下!!
喵喵时光机
交互式爱情
相关分类