請參照以下的原代碼,注意:可以替換JavaScript碼中的2007
以下是網頁原始碼
<!-- 分三步完成全部指令碼:
1. 將第一部分粘貼到HTML的HEAD區
2. 將OnLoad事件加入BODY標籤內
3. 將最後一部分代碼加入BODY區 -->
<!-- 第一步: 將如下代碼粘貼到HTML的HEAD區-->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var Temp2;
var timerID = null;
var timerRunning = false;
function arry() {
this.length = 12;
this[0] = 31;
this[1] = 28;
this[2] = 31;
this[3] = 30;
this[4] = 31;
this[5] = 30;
this[6] = 31;
this[7] = 31;
this[8] = 30;
this[9] = 31;
this[10] = 30;
this[11] = 31;
}
var date = new arry();
function stopclock() {
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock() {
stopclock();
showtime();
}
function showtime() {
now = new Date();
var CurMonth = now.getMonth();
var CurDate = now.getDate();
var CurYear = now.getFullYear();
now = null;
if (1 < CurDate) {
CurDate -= date[CurMonth]; CurMonth++;
}
if (0 < CurMonth) {
CurMonth -= 12; CurYear++;
}
var Yearleft = 2007 - CurYear;
var Monthleft = 0 - CurMonth;
var Dateleft = 1 - CurDate;
document.dateform.a.value = Yearleft;
document.dateform.b.value = Monthleft;
document.dateform.c.value = Dateleft;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
// End -->
</script>
</HEAD>
<!-- 第二步:將OnLoad事件加入BODY標籤內 -->
<BODY Onload="startclock()">
<!-- 第三步:將最後一部分代碼加入BODY區 -->
<form name=dateform>距離2007還有
<input type=text name=a size=2 value="">年
<input type=text name=b size=2 value="">月
<input type=text name=c size=2 value="">天
</form>
<!-- 代碼長度: 1.95 KB -->