叶公问政近者说:如何用vbscript做一个在页面上动态显示时间的程序啊

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 09:15:01
能不能仔细一点
做出来最好
高分回报,还有加分!!!!!

下面这个代码是显示一个按钮,按钮上显示当前时间,点击显示停留时间。

<script language="vbscript">
dim stt,edt
sub disp_clock()
dim hr,sx,hrs,curtime
hr=hour(time)
if hr<12 then
hrs=cstr(hr)
sx=" am"
else
hrs=cstr(hr-12)
sx=" pm"
end if
curtime=hrs+right(cstr(time),6)
yt.value=curtime+sx
call settimeout("disp_clock()",1000)
end sub

sub disp_msg()
dim hr,mn,sc,hrs,mns
edt=time
hr=hour(edt)
mn=minute(edt)
sc=second(edt)-second(stt)
if sc<0 then
sc=60+sc
mn=mn-1
end if
mn=mn-minute(stt)
if mn<0 then
mn=60+mn
hr=hr-1
end if
hr=hr-hour(stt)
if hr<0 then hr=24+hr
hrs=" "+cstr(hr)+"小时"
if hr=0 then hrs=""
mns=cstr(mn)+"分钟"
if mn=0 then mns=""
msgbox "你在本网页已停留了"+hrs+mns+cstr(sc)+"秒!"
end sub
</script>

<input type="button" value="" name="yt" onclick="disp_msg()">
<p><h5>提示:鼠标单击按钮会显示停留时间!</h5></p>

<script language=vbscript>
stt=time
disp_clock
</script>

如果你只是想动态显示时间,可以把下面代码加入你的页面:

<script language="vbscript">
dim stt,edt
sub disp_clock()
dim hr,sx,hrs,curtime
hr=hour(time)
if hr<12 then
hrs=cstr(hr)
sx=" am"
else
hrs=cstr(hr-12)
sx=" pm"
end if
curtime=hrs+right(cstr(time),6)
yt.innerHTML=curtime+sx
call settimeout("disp_clock()",1000)
end sub
</script>
<script language=vbscript>
stt=time
disp_clock
</script>

然后在需要出现时间的地方放上<span id="yt"></span>即可。

你要先确定网页空间是支持ASP的!

在网页的BODY中加入<%=now%>

就可以了!

如果你的空间支持ASP
现在的时间是:<%="now"%>就可以了
网上很多免费源码网站里都有的,你可以选择各式各样的时间

要是只是动态显示时间问题,不用非得支持ASP,网页脚本就可以办到