日期:2014-05-16 浏览次数:20388 次
<!DOCTYPE html> <html> <head><title>time</title> <script type="text/javascript" src="xxxx.js"></script> <meta http-equiv="Cache-Contorl" content="no-cache"/> </head> <body onload="time();"> </body> </html>
function time(){ var startTime=new Date(); var endTime=new Date(); var n=new Date(); var i; for(i=0;i<2;){ onmousedown=function(){if(i==0){startTime=n.getTime();i=1;}}; onmousedown=function(){if(i==1){endTime=n.getTime();i=2;}}; } n=endTime-startTime; alert(n); }
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> </style> </head> <body> <script> var times = []; document.onclick = function(){ if( !times.length ){ var t = new Date; times.push(t); }else{ var t = new Date; times.push(t); alert( '间隔 ' + (times[1] - times[0]) / 1000 + ' 秒' ); times.length = 0; // 情况记录 } } </script> </body> </html>