<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>即可。