步驟一 :
將以下程式碼複製 , 貼在網頁原始檔HTML<head> 與 </head> 之間 .
<script language="JavaScript">
<!--
var timerID = null
var timerRunning = false
function stopclock(){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function startclock(){
stopclock()
showtime()
}
function showtime(){
var now = new Date()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
if (hours>=6 && hours<=12)
{timeValue += ("上午")}
if(hours>12 && hours<=18)
{timeValue += ("下午")}
if(hours>18 && hours <=24)
{timeValue +=("晚上")}
if(hours<6)
{timeValue += ("凌晨")}
document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}
//-->
</script>
步驟二 :
將以下程式碼複製 , 貼在網頁原始檔HTML <body> 之內 .
onload="startclock();"
步驟三 :
將以下程式碼複製 , 貼在網頁原始檔HTML <body> 與 </body> 之間 .
<form name="clock" onsubmit="0">
<input type="text" size="9" name="face">
</form>