clock.asp
----------------------------------
< %
Response.Expires = -1
dim a
a=now()
Response.Write formatdatetime(a,2) & " " & formatdatetime(a,3)% >
-------------------------- ------
mytime.htm
----------------------------------
<html>
<body topmargin="0" leftmargin="0" style="background-color:#e0d0c0">
<table width="98%"><tr>
<td align="center" width="50%" style="font-size:16;font-weight:bold;">Changchun Rail Bus Co., Ltd. product plan price calculation program</td>
<td width="50%" align="right">
<input type="text" style="font-size:12px;border:none;background:;" size="18" id="myTime" />
</td>
</tr>
</table>
</body>
</html>
<script language="javascript">
//Simple method, implemented with the simplest code, but there are many potential errors
/*
function getClock()
{
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
XmlHttp.Open( "POST", "clock.asp", false );
XmlHttp.Send();
if (XmlHttp.status == 200) myTime.value=XmlHttp.responseText;
window.setTimeout("getClock()","1000")
}
setInterval("getClock()",1000);
*/
</script>
If you want to make the program more compatible and robust, you can change mytime.htm to the following
--------------------------- --------
mytime.htm
----------------------------------
<html>
<body topmargin="0" leftmargin="0" style="background-color:#e0d0c0">
<table width="98%"><tr>
<td align="center" width="50%" style="font-size:16;font-weight:bold;">Changchun Rail Bus Co., Ltd. product plan price calculation program</td>
<td width="50%" align="right">
<input type="text" style="font-size:12px;border:none;background:;" size="18" id="myTime" />
</td>
</tr>
</table>
</body>
</html>
<script>
//Complex method, adding a lot of detection and error handling
var xmlhttp, alerted
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
alert("Please install Microsofts XML parsers")
}
}
if (!xmlhttp && !alerted) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
alert("Your browser does not support the XMLHttpRequest object, please upgrade");
}
}
function getClock()
{
if (xmlhttp) {
xmlhttp.Open("Get","clock.asp",true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.send();
}
}
setInterval( "getClock()", 1000 );
functionRSchange()
{
if (xmlhttp.readyState==4) {
myTime.value = xmlhttp.responseText;
}
}
</script>