<html>
<head>
<script>
function RunTime(o)
{
var TimeDifference = new Date() - new Date(o.innerText.replace(/-/g,"/"));
(function ()
{
var d = new Date();
d.setTime(d.getTime()+TimeDifference);
o.innerText = d.toLocaleString();
setTimeout(arguments.callee,1000);
})();
}
</script>
</head>
<body onload="RunTime(document.getElementById('oTime'));">
服务器时间:<span id="oTime"><%=now%></span>
</body>
</html>
<head>
<script>
function RunTime(o)
{
var TimeDifference = new Date() - new Date(o.innerText.replace(/-/g,"/"));
(function ()
{
var d = new Date();
d.setTime(d.getTime()+TimeDifference);
o.innerText = d.toLocaleString();
setTimeout(arguments.callee,1000);
})();
}
</script>
</head>
<body onload="RunTime(document.getElementById('oTime'));">
服务器时间:<span id="oTime"><%=now%></span>
</body>
</html>
本文提供了一个使用JavaScript实现页面上显示的时间每秒自动更新的示例代码。该方法通过获取当前时间并利用setTimeout递归调用自身来实现时间的实时刷新。
98

被折叠的 条评论
为什么被折叠?



