lab1:建立顯示時間,自動跳秒 <html> <body onLoad="setck()" > <script> function dw(line) { document.write(line + "<br>"); } function setck() { var d = new Date(); var y = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); m = checkTime(m); s = checkTime(s); var now = y + ":" + m + ":" + s; document.getElementById("display").innerHTML = ("Now time:" + now); setTimeout(function(){setck()} , 1000); } function checkTime(i) { if(i<10){ i = "0" + i; } return i; } </script> <div id="display">dispaly</div> </body> </html> ---------------------------------------------------------------------------------------------------------------