<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示当前时间</title>
<script type="text/javascript">
function showtime(){//创建函数
var now_time = new Date();//创建时间对象的实例
var hours = now_time.getHours();//获得当前小时数
var minutes = now_time.getMinutes();//获得当前分钟数
var seconds = now_time.getSeconds();//获得当前秒数
var timer = ""+ ((hours>12)?hours -12:hours);//将小时数值赋予变量timer
timer+=((minutes<10)?":0":":")+minutes;//将分钟数赋予变量timer
timer+=((seconds<10)?":0":":")+seconds;//将秒数赋予timer
timer+=""+((hours>12)?" PM":" AM");//将字符AM或PM赋予变量timer
document.clock.show.value=timer;//在名为clock的表单中输出变量timer的值
setTimeout("showtime()",1000);//设置每隔一秒钟自动调用一次showtime()函数
}
</script>
</head>
<body onload="showtime()" >
<form name="clock" onsubmit="0">
<input type="text" name="show" size="10"
style=" border- 3;">
</form>
</script>
</body>
</html>