请问如何在网页中实现定时器的功能?

我想在网页中(客户端)嵌入一个如VB中的timer控件一样功能的定时器,请问有没有现成的控件或ASP自带的方法,谢谢!
---------------------------------------------------------------

settimeout

 1<html>
 2<head>
 3<title>开始</title>
 4<meta content="Microsoft Visual Studio 6.0" name="GENERATOR"/>
 5<link href="images/style.css" rel="stylesheet" type="text/css"/>
 6<style>   
 7td{background-color:#FFFFFF;}   
 8</style>
 9</head>
10<script language="JAVASCRIPT">   
11  
12var timerID = null   
13var timerRunning = false   
14  
15function MakeArray(size) {   
16this.length = size;   
17for(var i = 1; i <= size; i++){   
18this[i] = "";   
19}   
20return this;   
21}   
22  
23function stopclock (){   
24if(timerRunning)   
25clearTimeout(timerID);   
26timerRunning = false   
27}   
28  
29function showtime (){   
30var now = new Date();   
31var year = now.getYear();   
32var month = now.getMonth() + 1;   
33var date = now.getDate();   
34var hours = now.getHours();   
35var minutes = now.getMinutes();   
36var seconds = now.getSeconds();   
37var day = now.getDay();   
38Day = new MakeArray(7);   
39Day[0]="星期天";   
40Day[1]="星期一";   
41Day[2]="星期二";   
42Day[3]="星期三";   
43Day[4]="星期四";   
44Day[5]="星期五";   
45Day[6]="星期六";   
46var timeValue = "";   
47timeValue += year + "年";   
48timeValue += ((month < 10) ? "0" : "") + month + "月";   
49timeValue += date + "日 ";   
50timeValue += (Day[day]) + " ";   
51timeValue += ((hours <= 12) ? hours : hours - 12);   
52timeValue += ((minutes < 10) ? ":0" : ":") + minutes;   
53timeValue += ((seconds < 10) ? ":0" : ":") + seconds;   
54timeValue += (hours < 12) ? " AM" : " PM";   
55document.all.clock.innerText = timeValue;   
56timerID = setTimeout("showtime()",1000);   
57timerRunning = true   
58}   
59  
60function startclock () {   
61stopclock();   
62showtime()   
63}   
64  
65</script>
66<body onload="startclock()">
67<p align="right" style="margin-right:0;margin-top:10%;">
68<font size="-1"><b>现在是 </b></font><input id="clock" name="clock" size="40" style="color:red;border:0"/>
69</p>
70</body>
71</html>

---------------------------------------------------------------

//=====================================
// Class: JSTimer, interval is 0.1 second
// After each interval, the timer will triger the timer action
// Constructor: new JSTimer(timerAction)
// timerAction: js-statement when the timer trigered.
// Properties:
// .timerAction - js-statement when the timer trigered
// .index - the registered JSTimer index
// .timer - the system timer handler
// Methods:
// .start - start the timer triger
// .stop - stop the timer triger
//=====================================
var JSTimerRegister = new Array(); // A list of JSTimer object.
function JSTimer(timerAction){
this.timerAction = timerAction;
this.index = JSTimerRegister.length++;
this.timer = "";
this.stop = function(){
if(this.timer!="") window.clearInterval(this.timer);
this.timer = "";
};
this.start = function(){
if(this.timer!="")this.stop();
var statement = "eval(JSTimerRegister["+this.index+"].timerAction)";
this.timer = window.setInterval(statement, 100);
};
JSTimerRegister[this.index] = this;
}

---------------------------------------------------------------

up

Published At
Categories with Web编程
comments powered by Disqus