标签:
简介:通过JavaScript实现的钟表
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>2016-04-06 JavaScript-钟表</title>
<script>
function clock(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=check(m);
s=check(s);
document.getElementById(‘txt‘).innerHTML=h+":"+m+":"+s;
t=setTimeout("clock()",500); //关键点
function check(d){
if(d<10){
d="0"+d;
return d;
}else{
return d;
}
}
}
</script>
</head>
<body onload="clock()">
<div id="txt"></div>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/liuadou/p/5360242.html