<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
var timer=null;
function displayClock(num){//num是传入的startClock中的动态值
if(num<10){
return "0"+num;
}
else{
return num;
}
}
//停止计时
function stopClock(){
clearTimeout(timer);
}
//开始计时
function startClock(){
var time =new Date();
var hours=displayClock(time.getHours())+":";
var minutes=displayClock(time.getMinutes())+":";
var seconds=displayClock(time.getSeconds());
//显示时间
show.innerHTML=hours+minutes+seconds;//在id为show的块区域显示
timer=setTimeout("startClock()",1000);//延时器
}
</script>
</head>
<style>
#show{
font-size: 24px;
color:#4213C9;
text-align:center;
}
</style>
<body οnlοad="startClock()" οnunlοad="stopClock()">
<div id="show"></div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
var timer=null;
function displayClock(num){//num是传入的startClock中的动态值
if(num<10){
return "0"+num;
}
else{
return num;
}
}
//停止计时
function stopClock(){
clearTimeout(timer);
}
//开始计时
function startClock(){
var time =new Date();
var hours=displayClock(time.getHours())+":";
var minutes=displayClock(time.getMinutes())+":";
var seconds=displayClock(time.getSeconds());
//显示时间
show.innerHTML=hours+minutes+seconds;//在id为show的块区域显示
timer=setTimeout("startClock()",1000);//延时器
}
</script>
</head>
<style>
#show{
font-size: 24px;
color:#4213C9;
text-align:center;
}
</style>
<body οnlοad="startClock()" οnunlοad="stopClock()">
<div id="show"></div>
</body>
</html>