用setTimeout实现毫秒级动态时间显示

<!--版权所有:烟台大学2012级王洋-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Demo</title>
<script type="text/javascript">
function openClock()
{
	var obj = document.getElementById("Time");
	var s = new Date();
	obj.innerHTML = s.getHours()+":"+s.getMinutes()+":"+s.getSeconds()+":"+s.getMilliseconds();
	ID = setTimeout("openClock()",1);
}
</script>
<style type="text/css">
body{ background-color:#fff}
p{ color:#0066CC}
#title{font-size:50px; text-align:center; font-family:"Courier New", Courier, monospace; font-weight:bold}
#Time{ font-size:150px; text-align:left color:#0033FF;margin-left:300px;margin-top:10px;position:relative;}</style>
</head>

<body>
<form action="" name="form1">
<input type="button" value="点击显示时间" οnclick="openClock();" /><input type="button" value="点击暂停时间" οnclick="clearTimeout(ID);" />
</form>
<p id="title">Time by time</p><hr style="box-shadow:0px 0px 4px #000"/>
<p id = "Time"></p>
</body>
</html>

显示效果如下


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值