阿瑟 發表
製作Javascript時鐘其實一點也不難, 只要將setTimeout() 再加上innerHTML去運用就可以完成!!
<script language="JavaScript"> <!-- var now,hours,minutes,seconds,timeValue; function showtime(){ now = new Date(); hours = now.getHours(); minutes = now.getMinutes(); seconds = now.getSeconds(); timeValue = (hours >= 12) ? "下午 " : "上午 "; timeValue += ((hours > 12) ? hours - 12 : hours) + " 點"; timeValue += ((minutes < 10) ? " 0" : " ") + minutes + " 分"; timeValue += ((seconds < 10) ? " 0" : " ") + seconds + " 秒"; clock.innerHTML = timeValue; setTimeout("showtime()",1000); } showtime(); //--> </script> <body onload="showtime();" > <span id='clock'></span> |