1. 程式人生 > >製作時鐘特效

製作時鐘特效

在網頁上顯示當前時間 

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>顯示動態時鐘</title>
		<script type="text/javascript">
			var time;

			function clock() {
				var date = new Date();
				var s = date.getFullYear() + "年" +
					(date.getMonth() + 1) + "月" +
					date.getDate() + "日" +"星期"+date.getDay()+"<br/>"+
					date.getHours() + ":" +
					date.getMinutes() + ":" +
					date.getSeconds();
				document.getElementById("clockContent").innerHTML = s;
			}

			function clockGo() {
				time = setInterval("clock()", 1000);
			}

			function clockStop() {
				clearInterval(time);
			}
		</script>

	</head>

	<body>
		<input type="button" value="時鐘開始" onclick="clockGo()" /><br />
		<input type="button" value="時鐘暫停" onclick="clockStop()" /><br />
		<span id="clockContent">s時鐘在此顯示</span>
	</body>

</html>