<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>通过定时器显示当前时间</title>
<script>
var s;
window.οnlοad=function(){
s = window.setInterval("shijian()",1000)
}
function shijian(){
var sdom = document.getElementById("spantime");
var now = new Date();//用来得到当前时间
var stime = now.getFullYear()+"年"+(now.getMonth()+1)+"月"
+now.getDate()+"日"+now.getHours()+"时"
+now.getMinutes()+"分"+now.getSeconds()+"秒";
sdom.innerHTML=stime;
}
function tingzhi(){
window.clearInterval(s);//停止定时器
}
function kaishi(){
s=window.setInterval("shijian()",1000)
}
</script>
</head>
<body>
<span id="spantime"></span>
<input type="button" value="停止" οnclick="tingzhi()">
<input type="button" value="开始" οnclick="kaishi()">
</body>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>通过定时器显示当前时间</title>
<script>
var s;
window.οnlοad=function(){
s = window.setInterval("shijian()",1000)
}
function shijian(){
var sdom = document.getElementById("spantime");
var now = new Date();//用来得到当前时间
var stime = now.getFullYear()+"年"+(now.getMonth()+1)+"月"
+now.getDate()+"日"+now.getHours()+"时"
+now.getMinutes()+"分"+now.getSeconds()+"秒";
sdom.innerHTML=stime;
}
function tingzhi(){
window.clearInterval(s);//停止定时器
}
function kaishi(){
s=window.setInterval("shijian()",1000)
}
</script>
</head>
<body>
<span id="spantime"></span>
<input type="button" value="停止" οnclick="tingzhi()">
<input type="button" value="开始" οnclick="kaishi()">
</body>
</html>
显示当前时间,有停止和开始两个按钮