哪位帮忙写出一下如何精确到毫秒,就是秒后面加小数点!弄了半天没弄好,本人菜鸟
<SCRIPT LANGUAGE="JavaScript">   
<!--   
var maxtime = 60*60 //一个小时,按秒计算,自己调整! 
function CountDown(){   
if(maxtime>=0){
hours = Math.floor(maxtime/1800);   
minutes = Math.floor(maxtime/3600);   
seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+hours+"小时"+minutes+"分"+seconds+"秒";   
document.all["timer"].innerHTML=msg;   
if(maxtime == 5*60) alert('注意,还有5分钟!');   
--maxtime;   
}   
else{   
clearInterval(timer);   
alert("时间到,结束!");   
}   
}   
timer = setInterval("CountDown()",1000);   
//-->   
</SCRIPT>   
<div id="timer" style="color:red; font-size:28px"></div>   

解决方案 »

  1.   

    <body>
    <div id="timer" style="color:red; font-size:28px"></div> 
    </body>
    <SCRIPT LANGUAGE="JavaScript">   
    <!-- 
    var maxtime =1000 * 60 * 60 * 24 * 2; //截止时间:为当前计算机时间+2天
    var EndTime = new Date(new Date().getTime() + maxtime);  
    function CountDown(){
    NowTime = new Date();  
    var nMS = EndTime.getTime() - new Date().getTime();  
    var nD = Math.floor(nMS / (1000 * 60 * 60 * 24));  
    var nH = Math.floor(nMS / (1000 * 60 * 60)) % 24;  
    var nM = Math.floor(nMS / (1000 * 60)) % 60;  
    var nS = Math.floor(nMS / 1000) % 60;  
    var nMS = Math.floor(nMS / 100) % 10;
    if(nS>=0){
    msg = "距离结束还有"+nD+"天"+nH+"小时"+nM+"分"+nS + "." + nMS+"秒";
    document.all["timer"].innerHTML=msg;   
    if(nM+nS+nMS == 5){ 
    alert('注意,还有5分钟!'); 
    }
    }else{   
    alert("时间到,结束!");   
    }   
    setTimeout("CountDown()",100); 
    }
    CountDown();
    //-->   
    </script>