一个很简单的代码,不过也是偶练习的作品,顺便贴出来纪念下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
function clock(){
var nowtime=new Date();
var flag="AM";
var hours=nowtime.getHours();
if(hours>12){
hours-=12;
flag="PM";
}
hours=hours>9?hours:"0"+hours;
var minutes=nowtime.getMinutes();
minutes=minutes>9?minutes:"0"+minutes;
var seconds=nowtime.getSeconds();
seconds=seconds>9?seconds:"0"+seconds;
var disptime=hours+":"+minutes+":"+seconds+" "+flag;
document.getElementById("clock").innerHTML=disptime;
setTimeout("clock()",1000);
}
</script>
</head>
<body>
<div id="clock"></div>
<script type="text/javascript">
clock();
</script>
</body>
</html>