国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Javascript利用xmlhttp獲得服務器時鐘的方法

2019-11-18 19:06:28
字體:
來源:轉載
供稿:網友

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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳平市| 四子王旗| 米脂县| 拉萨市| 纳雍县| 宿州市| 黔东| 长海县| 星子县| 尼木县| 新晃| 五原县| 遵义市| 临澧县| 孟津县| 城固县| 天峻县| 乾安县| 兴安盟| 天柱县| 临颍县| 章丘市| 泉州市| 寿阳县| 张家界市| 福鼎市| 枞阳县| 礼泉县| 卢龙县| 昌图县| 桦南县| 洞头县| 乐陵市| 泰宁县| 文化| 雅江县| 万全县| 册亨县| 玛纳斯县| 安图县| 郎溪县|