<html> <head> <script language="JavaScript"> var time1Object=new Date(); var time1=time1Object.getTime(); function timeCha() { var time2Object=new Date(); var time2=time2Object.getTime(); return((time2-time1)/1000); }
function timestop() { //总秒数; var total=Math.round(timeCha()); //总分钟数; var temp=total%60; //秒数=总秒数-总的分钟数*60; var miaozhong=(total-(temp*60)); //小时=总分钟%60; var xiaoshi=temp%60; //分钟=总分钟-小时*60; var fenzhong=(temp-(xiaoshi*60));
var H=""+((xiaoshi>9)?xiaoshi:"0"+xiaoshi); var S=""+((fenzhong>9)?fenzhong:"0"+fenzhong); var M=""+((miaozhong>9)?miaozhong:"0"+miaozhong); document.form1.text1.value=""+H+":"+S+":"+M; window.setTimeout("timestop()",1000); } </script> </head> <body onLoad="timestop();"> <form name="form1"> 停留时间<input type="text" name="text1" size=30> </form> </body> </html> 想记算进入网页停留的时间,却不知道出了什么问题,问题很奇怪,请高手运行代码后再下结论,谢谢.