<html>
<head>
<script Language="JavaScript">
var timerID = null;//设置变量timeID,其为null数据类型。
var timerRunning = false;//设置变量timeRunning,其为布尔型。
function stopclock (){//定义一个函数。
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
/*如果timeRunning的值是真,则取消延时操作,并将timeRunning的值设为假。*/
}
function showtime () {//定义一个函数,名为showtime。
var now = new Date();//定义now为一个新的时间对象。
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
/*分别定义变量hours,minutes,seconds的值为现在时间的小时,分,秒。*/
var timeValue = "" + ((hours >12) ? hours -12 :hours)//定义变量timeValue的值为当小时数大于12时,则小时数减12。
timeValue += ((minutes < 10) ? ":0" : ":") + minutes//设置timeValue的值为小时数加分钟数,当分钟数小于10时,前面加0。
timeValue += ((seconds < 10) ? ":0" : ":") + seconds//设置timeValue的值为小时数加分钟数加秒数,当秒数小于10时,前面加0。
timeValue += (hours >= 12) ? " P.M." : " A.M."//设置timeValue的值为小时数加分钟数加秒数再加一个PM或AM。
window.status = timeValue;//在状态栏内显示timeValue的值。
timerID = setTimeout("showtime()",1000);//设置一个时间间隔,为1秒,每一个时间间隔调用一次showtime()函数。
timerRunning = true;//设置timerRunning 的值为真。
}
function startclock () {//定义一个函数startclock 。
stopclock();
showtime();
/*调用startclock 函数和showtime函数。*/
}
</script>
</head>
<body onLoad="startclock()"><!--页面加载时,调用startclock()函数-->
</body>
</html>
<head>
<script Language="JavaScript">
var timerID = null;//设置变量timeID,其为null数据类型。
var timerRunning = false;//设置变量timeRunning,其为布尔型。
function stopclock (){//定义一个函数。
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
/*如果timeRunning的值是真,则取消延时操作,并将timeRunning的值设为假。*/
}
function showtime () {//定义一个函数,名为showtime。
var now = new Date();//定义now为一个新的时间对象。
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
/*分别定义变量hours,minutes,seconds的值为现在时间的小时,分,秒。*/
var timeValue = "" + ((hours >12) ? hours -12 :hours)//定义变量timeValue的值为当小时数大于12时,则小时数减12。
timeValue += ((minutes < 10) ? ":0" : ":") + minutes//设置timeValue的值为小时数加分钟数,当分钟数小于10时,前面加0。
timeValue += ((seconds < 10) ? ":0" : ":") + seconds//设置timeValue的值为小时数加分钟数加秒数,当秒数小于10时,前面加0。
timeValue += (hours >= 12) ? " P.M." : " A.M."//设置timeValue的值为小时数加分钟数加秒数再加一个PM或AM。
window.status = timeValue;//在状态栏内显示timeValue的值。
timerID = setTimeout("showtime()",1000);//设置一个时间间隔,为1秒,每一个时间间隔调用一次showtime()函数。
timerRunning = true;//设置timerRunning 的值为真。
}
function startclock () {//定义一个函数startclock 。
stopclock();
showtime();
/*调用startclock 函数和showtime函数。*/
}
</script>
</head>
<body onLoad="startclock()"><!--页面加载时,调用startclock()函数-->
</body>
</html>