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;">長春軌道客車股份有限公司產品計畫價格計算程式</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">
//簡單方法,用最簡單的程式碼實現,但是有很多錯誤隱患的
/*
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>
如果為了能讓程式的相容性和健全性更強,可以將mytime.htm改成如下的
--------------------------- --------
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;">長春軌道客車股份有限公司產品計畫價格計算程式</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>
//複雜方法,增加了很多檢測,和錯誤處理
var xmlhttp,alerted
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
alert("請安裝Microsofts XML parsers")
}
}
if (!xmlhttp && !alerted) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
alert("你的瀏覽器不支援XMLHttpRequest對象,請升級");
}
}
function getClock()
{
if (xmlhttp) {
xmlhttp.Open("Get","clock.asp",true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.send();
}
}
setInterval( "getClock()", 1000 );
function RSchange()
{
if (xmlhttp.readyState==4) {
myTime.value = xmlhttp.responseText;
}
}
</script>