51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> asp.net >> 文章正文

asp显示当前时间并更新

更新时间:2012-5-3:  来源:51代码网

time.htm 页面
===============================================================
<div id="box"></div>
<script>
function $(ID) {
if (document.getElementById && document.getElementById(ID)) {
return document.getElementById(ID);
} else if (document.all && document.all(ID)) {
return document.all(ID);
} else if (document.layers && document.layers[ID]) {
return document.layers[ID];
} else {
return false;
}
}
function AJAX() {
var $HTTP = false;
var $Me = this;
try {
$HTTP = new XMLHttpRequest;
} catch(e) {
try {
$HTTP = new ActiveXObject("MSXML2.XMLHTTP");
} catch(e2) {
try {
$HTTP = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e3) {
$HTTP = false;
}
}
}
if (!$HTTP) {return false;}
this.method = "POST";
this.URL;
this.ASYNC = true;
this.content = "";
this.callback = function(obj) {return obj;}
this.send = function() {
if (!this.method||!this.URL||!this.ASYNC) {return false;}
$HTTP.open(this.method,this.URL,this.ASYNC);
if (this.method == "POST") {$HTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
$HTTP.onreadystatechange = function() {$Me.callback($HTTP);}
if (this.method == "POST") {$HTTP.send(this.content);} else {$HTTP.send(null);}
}
}
function getTime() {
var Ajax = new AJAX();
Ajax.method = "GET";
Ajax.URL = "time.asp?do=ok";
Ajax.callback = function($HTTP) {
if ($HTTP.readyState == 4) {
$("box").innerHTML = $HTTP.responseText;
} else {}
}
Ajax.send();
}
setInterval("getTime();",1000);
</script>
===============================================================

asp 页面
===============================================================
<%
if request("do") = "ok" then
response.write now
end if
%>

<SCRIPT Language="VBScript"> 
dim moTime 

function showTime() 
document.all.spnTime.innerText = Formatdatetime(now(),0) 
end function 

moTime = setInterval("showTime()",1000) 

</SCRIPT> 

<span id="spnTime">当前时间</span>

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |