<div class="htmlarea"> <textarea id="runcode43720"> <style> #PPQTime{ font-size:36px; color:black; font-weight:bold; } </style> <script> function Clock() { var Today=new Date(); var PPQday=new Date(2010,9-1,28); var DayTime = (PPQday.getTime()-Today.getTime())/ 1000 / 60 / 60 /24; var days = parseInt(DayTime);//天 var HourTime =(DayTime - days)*24; var hours =parseInt(HourTime);//时 var MinutesTime =(HourTime-hours)*60; var minutes = parseInt(MinutesTime);//分 var SecondTime =(MinutesTime-minutes)*60; var seconds = parseInt(SecondTime); //秒 var MillisecondTime = (SecondTime-seconds)*100;//取2位 var milliseconds = parseInt(MillisecondTime);//毫秒 document.getElementById("PPQTime").innerHTML= "距宝宝出生还有 "+ days + "天"+ ForMat(hours)+"小时"+ForMat(minutes)+"分"+ForMat(seconds)+"秒"+ForMat(milliseconds)+"毫秒"; setTimeout(Clock,100); } function ForMat(data) { if(data<10) return "0"+data; else return data; } </script> <div id="PPQTime"></div> </textarea><br><input onclick="runEx('runcode43720')" type="button" value="运行代码"> <input onclick="doCopy('runcode43720')" type="button" value="复制代码"> <input onclick="doSave(runcode43720)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>上面的代码主要用到了javascript日期处理技巧与setTimeout实现日期的刷新。