哦,问题解决了,我修改了一下代码如下:
<html>
<head>
<title>载网页上显示时间</title>
</head><body>
<script language = "javascript">
id = window.setTimeout("output()",0);
function output(){
now = new Date();
hours = now.getHours();
mins = now.getMinutes();
secs = now .getSeconds();
document.form1.input1.value =hours + ":" + mins + ":" + secs ;
window.status = "当前时间是:" + hours + ":" + mins + ":" + secs;
id = setTimeout("output()",1000);
}
</script>
<hr>
<form name = "form1">
<input type = "text" name = "input1" size = "20"><br>
<input type = "button" value = "stop" onclick = "clearTimeout(id);">
</form>
<hr></body>
</html>
这样修改后就可以每次执行output()函数后都重新载入当前的时间。
还有点问题,就是stop按钮不起作用。难道是clearTimeout()的用法不对么?
请指点!谢谢!
<html>
<head>
<title>载网页上显示时间</title>
</head><body>
<script language = "javascript">
id = window.setTimeout("output()",0);
function output(){
now = new Date();
hours = now.getHours();
mins = now.getMinutes();
secs = now .getSeconds();
document.form1.input1.value =hours + ":" + mins + ":" + secs ;
window.status = "当前时间是:" + hours + ":" + mins + ":" + secs;
id = setTimeout("output()",1000);
}
</script>
<hr>
<form name = "form1">
<input type = "text" name = "input1" size = "20"><br>
<input type = "button" value = "stop" onclick = "clearTimeout(id);">
</form>
<hr></body>
</html>
这样修改后就可以每次执行output()函数后都重新载入当前的时间。
还有点问题,就是stop按钮不起作用。难道是clearTimeout()的用法不对么?
请指点!谢谢!
var ida = window.setTimeout( "output() ",0);
function output(){
now = new Date();
hours = now.getHours();
mins = now.getMinutes();
secs = now .getSeconds();
document.form1.input1.value =hours + ": " + mins + ": " + secs ;
window.status = "当前时间是: " + hours + ": " + mins + ": " + secs;
ida = setTimeout("output()",1000);
}
</script>
<hr>
<form name ="form1">
<input type = "text" name = "input1" size = "20 "> <br>
<input type = "button" value = "stop " onclick = "clearTimeout(ida);">
</form>
难道用来存储超时设定的标识符有特别的规定么?