这段JavaScript的超时功能代码怎么运行不了呢?

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:30:37
以下是一段时间JavaScript的超时功能的代码。可是当我把它载入浏览器时却运行不了。我仔细检查了,找不出哪有错误。和浏览器版本有关吗?期待高手指点!谢谢!
代码中的window.setTimeout()方法用于实现超时功能。

<html>
<head><title>超时功能例子</title>
<script language="Javascript" type="text/javascript">
var counter=0;
ID=window.setTimeout("Update();",2000);
function Update()
{
counter++;
document.form1.input1.value="The counter is now at " + counter;
ID=window.setTimeout("Update();"2000);
}
</script>
</head>
<body>
<h1>超时功能例子</h1>
<hr><p>
The text value below is being updated every two seconds.Press the RESET button to restart the count,or the STOP button to stop it.
</p></hr>
<form NAME="form1">
<input TYPE="text" NAME="input1" size="40"><br>
<input TYPE=

function Update()
{
counter++;
document.form1.input1.value="The counter is now at " + counter;
ID=window.setTimeout("Update();"2000);
}

里面的ID=window.setTimeout("Update();"2000);少了逗号,看见没?你以后用firefox来调试程序吧,再装一个firebug插件,这类语法错误你还没开始运行它就已经提示你了。大大缩短你的开发时间。

<html>
<head><title>超时功能例子</title>
<script language="Javascript" type="text/javascript">
var counter=0;
ID=window.setTimeout("Update();",2000);
function Update()
{
counter++;
document.form1.input1.value="The counter is now at " + counter;
ID=window.setTimeout("Update();",2000);
}
</script>
</head>
<body>
<h1>超时功能例子</h1>
<hr><p>
The text value below is being updated every two seconds.Press the RESET button to restart the count,or the STOP button to st