JS案例:动态显示实时时间

来自CloudWiki
跳转至: 导航搜索
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>页面电子时钟实现案例</title>
</head>
<body>
<p id="clock">显示电子时钟的位置</p>
<script type="text/javascript">
	function ShowTime(){
	    var now,clock_line,time_text;
	    now=new Date();
	    time_text = now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
	    clock_line = document.getElementById("clock"); // 获取 clock 段落元素对象
	    clock_line.innerText = time_text; //设置段落文本
	    setTimeout("ShowTime();",200); //设置延时器
	}
    ShowTime();
</script>
</body>
</html>