码迷,mamicode.com
首页 > Web开发 > 详细

JS显示时间

时间:2015-09-16 15:40:18      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

HTML CODE:

<!DOCTYPE html>
<html>
<head>
<title>JS</title>
<meta charset="utf-8">
<script src="foo.js"></script>
</head>
<body onload="startTime()">
<div id="timetxt"></div>
</body>
</html>

JS CODE:

function startTime(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById("timetxt").innerHTML = h+":"+m+":"+s;
t = setTimeout(function(){
startTime();
},500);

}

function checkTime(i){
if(i<10){
i = "0"+i;
}
return i;
}

JS显示时间

标签:

原文地址:http://www.cnblogs.com/htmlphp/p/4813363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!