简单的秒表实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>日期对象</title> </head> <body> <div id="div">16:30:00</div> <script> function getDate(){ var myDiv = document.getElementById("div"); var tt = new Date(); var hover = tt.getHours(), minute = tt.getMinutes(); second = tt.getSeconds(); if(hover < 10){ hover = "0" + hover; } if(minute < 10){ minute = "0" + minute; } if(second < 10){ second = "0" + second; } var time = hover+":"+minute+":"+second; myDiv.innerHTML = time; }; getDate();//以免第一次还要等待30毫秒; setInterval(getDate,30) </script> </body> </html>