js demo setTimeout

写了一个js中的setTimeout函数的例子。这个函数的功能主要是设置一个时间,时间结束之后执行第一个参数代表的js代码。例子如下

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Timeout Example</title>
<script type="text/javascript">
var counter=0;
ID=window.setTimeout("Update()",1000);
function Update(){
	counter++;
	document.form1.input1.value="The counter is now at "+counter;
	ID=window.setTimeout("Update()",1000);
}

</script>
</head>
<body>
<h1>Timeout Example</h1>
<hr>
<p>The text value below is being updated every two seconds.
Reress the RESET button to reset the count,or the STOP button
 to stop it.</p>
<hr>
<form name="form1">
<input type="text" name="input1" size="40"/><br />
<input type="button" value="RESET" οnclick="counter=0;"><br/>
<input type="button" value="STOP" οnclick="window.clearTimeout(ID);">
</form>
</body>
</html>

我试图将form元素去掉。input元素设置值那句话改成:document.input1.value="something...";

这时控制台会报错 docum.input1.value is undefined 。看来这里的form1元素是不能缺少的。

功力尚浅。还需练习啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值