JS中的setTimeout和setInterval的区别

Posted on 2007-03-22 20:46 Jaunt 阅读(666) 评论(0)  编辑  收藏 所属分类: JavaScript
setTimeout(Expression,DelayTime),在DelayTime过后,将执行一次Expression
setInterval(expression,delayTime),每个DelayTime,都将执行Expression

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  
<title></title>
</head>
<body>
<div id="a"></div>
<div id="b"></div>
<script type="text/javascript">
setTimeout(
"document.getElementById('a').innerHTML=
new Date().getSeconds();
",1000);
setInterval(
"document.getElementById('b').innerHTML=
new Date().getSeconds();
",1000);
  
</script>
</body>
</html>
From:http://www.cnitblog.com/yemoo/archive/2006/06/29/13078.html

只有注册用户登录后才能发表评论。


网站导航: