倒计时的秒数显示不正常。太慢点解。。。 ??
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h2>毫秒的倒计时</h2> <div id="timer2"></div> <script> var countdown = function(gid,time){ try { if (time<=0) { } else { var ms = Math.floor(time%1000); var s = Math.floor(time/1000%60); var m = Math.floor(time/1000/60%60); var h =Math.floor(time/1000/60/60%24); h=h>9?h:'0'+h; m=m>9?m:'0'+m; s=s>9?s:'0'+s; ms=ms>9?ms:'0'+ms; if (parseInt(h)>0) { var str = h+':'+m+':'+s; } else { var str = m+':'+s+':'+ms; } document.getElementById('timer2').innerHTML = str; setTimeout(function(){ countdown(gid,time-1); },1); } } catch (e) { if (typeof(console) == 'object') { console.log(e); } } }; setTimeout(function(){countdown('timer2',99999)},1); </script> </body> </html> 