首页 > 代码库 > 用原生javascript实现在页面动态显示时间

用原生javascript实现在页面动态显示时间

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>js demo1</title>
</head>
<body>
<script src="http://www.mamicode.com/cLanguage.js"> 

var t = null;
t = setTimeout(time,1000);
function time(){
clearTimeout(t);
dt = new Date();
var h = dt.getHours();
var m = dt.getMinutes();
var s = dt.getSeconds();
document.getElementById("timeShow").innerHTML="现在的时间:" + h + "时" + m + "分" + s + "秒";
t = setTimeout(time,1000);
}

</script>
<label id="timeShow"></lable>
</body>
</html>

用原生javascript实现在页面动态显示时间