Javascript 倒计时条不减少

Javascript 倒计时条不减少,javascript,countdown,Javascript,Countdown,我有一个倒计时进度条的JS代码,它应该取一个时间值并减少直到到达时间,然后显示过期 函数progresstimeleft,timetotal$元素{ var bar=document.getElementByIdprogressBar var progressBarWidth=timeleft*bar.width/timetotal console.logwidth为+bar.width+time left为+timeleft $element.finddiv.animate{ 宽度:prog

我有一个倒计时进度条的JS代码,它应该取一个时间值并减少直到到达时间,然后显示过期

函数progresstimeleft,timetotal$元素{ var bar=document.getElementByIdprogressBar var progressBarWidth=timeleft*bar.width/timetotal console.logwidth为+bar.width+time left为+timeleft $element.finddiv.animate{ 宽度:progressBarWidth },timeleft==timetotal?0:1000,线性 如果timeleft>0{ setTimeoutfunction{ progresstimeleft-1,timetotal$元素 }, 1000 } } progress180,180,$progressBar 这不应该吗

var bar = document.getElementById("#progressBar")
是这个吗

var bar = document.getElementById("progressBar")

这不应该吗

var bar = document.getElementById("#progressBar")
是这个吗

var bar = document.getElementById("progressBar")


您已经传入了$element,它是bar

函数progresstimeleft,timetotal$元素{ var progressBarWidth=timeleft*$element.width/timetotal console.log`width:${$element.width}px |剩余时间:${timeleft}秒` $element.finddiv.animate{ 宽度:progressBarWidth },timeleft==timetotal?0:1000,线性 如果timeleft>0{ setTimeoutprogress,1000,timeleft-1,timetotal$元素 } } progress60,60,$progressBar 进步酒吧部{ 背景:绿色; 高度:1米; }
您已经传入了$element,它是bar

函数progresstimeleft,timetotal$元素{ var progressBarWidth=timeleft*$element.width/timetotal console.log`width:${$element.width}px |剩余时间:${timeleft}秒` $element.finddiv.animate{ 宽度:progressBarWidth },timeleft==timetotal?0:1000,线性 如果timeleft>0{ setTimeoutprogress,1000,timeleft-1,timetotal$元素 } } progress60,60,$progressBar 进步酒吧部{ 背景:绿色; 高度:1米; }
谢谢,非常有指导性,希望我以后能避免这些新手的错误@Ste我添加了更多的技巧。请参阅更新后的回复。谢谢,非常有指导意义,希望我以后能避免这些新手错误@Ste我添加了更多提示/技巧。请参阅更新的响应。