動態顯示時間
<html>
<title></title>
<head>
<script language="JavaScript">
var timerID=null;
var timerRunning=false;
file://啟動
function startclock()
{
stopclock();
time();
}
file://停止
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning=false;
}
file://實現模組
function time()
{
file://使用new操作符建立時間對象
var now=new Date();
var yr=now.getYear();
var mName=now.getMonth()+1;
var dayNr=((now.getDate()<10)?"0":"")+now.getDate();
var dName=now.getDay()+1;
var ampm=(now.getHours()>=12)?"下午":"上午"
var hours=now.getHours();
hours=((hours>12)?hours-12:hours);
var minutes=((now.getMinutes()<10)?":0":":")+now.getMinutes();
var seconds=((now.getSeconds()<10)?":0":":")+now.getSeconds();
file://判斷今天是星期幾
if(dName==1)Day="Sunday";
if(dName==1)Day="Monday";
if(dName==3)Day="Tuesday";
if(dName==4)Day="Wednesday";
if(dName==5)Day="Thursday";
if(dName==6)Day="Friday";
if(dName==7)Day="Saturday";
file://判斷月份
if(mName==1)Month="Janauary";
if(mName==2)Month="February";
if(mName==3)Month="March";
if(mName==4)Month="April";
if(mName==5)Month="May";
if(mName==6)Month="June";
if(mName==7)Month="July";
if(mName==8)Month="August";
if(mName==9)Month="September";
if(mName=10)Month="October";
if(mName=11)Month="November";
if(mName=12)Month="December";
var DayOfWeek=(""+Day+"");
document.forms[0].elements[0].value=DayOfWeek;
var MonthDayYear=(""+Month+","+dayNr+","+yr+"");
document.forms[0].elements[1].value=MonthDayYear;
var TimeValue=(""+hours+minutes+seconds+""+ampm);
document.forms[0].elements[2].value=TimeValue;
timerID=setTimeout("time()",1000);
timerRunning=true;
}
</script>
</head>
<body onLoad="startclock()">
<form>
<table border=3 width=500>
<tr>
<td align="center"><FONT COLOR=800000 SIZE=+1><STRONG>今天星期</STRONG></FONT>
<td align="center"><input type="text"NAME="local"SIZE=13 VALUE="Weekday">
</tr>
<tr>
<td align="center"><font color=800000 size=+1><strong>日期</strong></font>
<td align="center"><INPUT TYPE="text" name="local" size=22 value="日期">
</tr>
<tr>
<td align="center"><font color=800000 size=+1><strong>時間</strong></font>
<td align="center"><input type="text" name="local" size=16 value="時間">
</tr>
</table>
<br>
<table border=0 widtn=400>
<tr>
<TD align="center"><input type="button" value="停止" onclick="stopclock()">
<TD align="center"><input type="button" value="繼續" onclick="startclock()">
</tr>
</table>
</form>
</html>