Javascript Countdown Timer
I need a count down timer that can display second:miliseconds format, I found one that I figured I could modify it to show this like 4:92 but it doesn't want to work for me for some reason. It works fine on the site, but I try and put it into my page, the console tells me:
Uncaught ReferenceError: display is not defined
.
What did I do wrong?
var milisec=0
var seconds=30
开发者_如何转开发 document.getElementById("timer").innerHTML='30'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.getElementById("timer").innerHTML=seconds+"."+milisec
setTimeout("display()",100)
}
display()
(original source)
Make it setTimeout( display, 100 )
so the literal is passed, otherwise it executes in global context and most likely that fn is not defined as a method of window ( maybe because you have it a window load anon literal? )
精彩评论