Javascript 设置超时后InnerText闪烁

Javascript 设置超时后InnerText闪烁,javascript,settimeout,innertext,Javascript,Settimeout,Innertext,我在学校项目之间做一个小项目,我在使用DOM元素时遇到问题,我使用innerText从一个时钟转到另一个文本,然后在5s之后,我想清空该文本。一切正常,但文本会在一段时间后闪烁 //中断时间//中断时间//中断时间//中断时间 让inputTime=document.getElementById('breakTimeInput'); document.querySelector(“#cta paus”).addEventListener('click',function(){ 如果(input

我在学校项目之间做一个小项目,我在使用
DOM
元素时遇到问题,我使用
innerText
从一个时钟转到另一个文本,然后在
5s
之后,我想清空该文本。一切正常,但文本会在一段时间后闪烁

//中断时间//中断时间//中断时间//中断时间
让inputTime=document.getElementById('breakTimeInput');
document.querySelector(“#cta paus”).addEventListener('click',function(){
如果(inputTime.value==''){
swal('Break Time'、'You忘了设置Break Time!'、'warning');
返回;
}
让breakTime=inputTime.value*60;
设置间隔(更新计数,1000);
函数updateCountdown(){
分钟=数学楼层(休息时间/60);
设秒=中断时间%60;
//在secunds前面添加零
秒=秒<10?'0'+秒:秒;
//超时
document.querySelector(
“#MyClockDisplayDown”
).innerText=`${minutes}:${seconds}`;
休息时间--;
//分钟结束时删除零
如果(分钟==0){
document.querySelector('#MyClockDisplayDown').innerText=`${seconds}`;
}
//如果倒计时结束,写一些文字
如果(中断时间<0){
document.querySelector(“#MyClockDisplayDown”).innerText='On Air';
inputTime.value='';
设置超时(()=>{
document.querySelector('#MyClockDisplayDown')。innerText='';
}, 2000);
}
}

});完成后需要调用
clearInterval
:仍然每秒调用
updateCountdown
函数

像这样的

。。。
document.querySelector(“#cta paus”).addEventListener('click',function(){
...
var intervalId=setInterval(updateCountdown,1000);
函数updateCountdown(){
...
//如果倒计时结束,写一些文字
如果(中断时间<0){
...
clearInterval(有效期内);//{
document.querySelector('#MyClockDisplayDown')。innerText='';
}, 2000);
}
}

您的代码段未运行。您应该添加运行该代码段所需的HTML。好的,谢谢,我将尝试:)