客户端:gettime.htm
<html>
<body onLoad=getClock();>
<SPAN id=time_area></SPAN>
</body>
</html>
<script language="javascript">
function getClock()
{
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
XmlHttp.Open( "POST","clock.asp", false );
XmlHttp.Send();
if (XmlHttp.status == 200) document.getElementById("time_area").innerHTML = XmlHttp.responseText;
window.setTimeout("getClock()","1000")
}
</script>
clock.asp
<%
Response.Write now()
%>
本文介绍了一个使用JavaScript实现客户端实时显示时间的例子。通过客户端页面的onLoad事件触发getClock函数,利用AJAX技术向服务器请求当前时间,并通过setTimeOut函数每秒更新一次时间显示。服务器端使用ASP返回当前系统时间。
1万+

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



