ASP做考勤系统,想在客户端显示服务器的当前时间并能够在客户端利用JS实时显示?也就是可以走动的时间?

2025-03-11 07:39:56
推荐回答(1个)
回答1:

我说说我的想法。用JS代码通过XMLHttp获取服务器时间动态刷新显示即可显示为当前时间。误差要求不是太大的话(考勤嘛)可以每20秒刷一次。
GetTime.asp (UTF-8编码)
=======================================
<%@LANGUAGE="VBSCRIPT.Encode" CODEPAGE="65001"%><%
Response.Expires = 0
%><%= Now() %>
=======================================

GetTime.js
-------------------------------
var xmlHttp = false;var tID;
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function ShowTime() {
clearInterval(tID);
var url = "GetTime.asp";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4&& xmlHttp.status == 200) {
var response = xmlHttp.responseText;
document.getElementById("ShowTime_Div").innerHTML=response;
}
}
xmlHttp.send(null);
tID = setInterval("ShowTime()",10000);//每10秒刷新
}
-------------------------------

test.htm
-----------------------------------------





-----------------------------------------
-----------------------------------------