setInterval不是循环执行么,怎么我这个只执行了一次啊

要做漂亮的美女IT人员 2010-02-05 11:30:41

<script language="javascript">
function a() {
var myDate = new Date();
var s = myDate.getSeconds();
document.write(s);
}
a();
setInterval('a()', 1000);
</script>
...全文
972 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
草根醉秋意 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 yingzhilian2008 的回复:]
引用 2 楼 calvindo 的回复:
JScript codefunction a() {var myDate=new Date();var s= myDate.getSeconds();
    document.write(s);
setInterval('a();',1000);

}

[/Quote]乱顶,误导……
yingzhilian2008 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 calvindo 的回复:]
JScript codefunction a() {var myDate=new Date();var s= myDate.getSeconds();
document.write(s);
setInterval('a();',1000);

}
[/Quote]顶
lihan6415151528 2010-02-06
  • 打赏
  • 举报
回复
document.write(s);

这里有问题
hwoarangzk 2010-02-05
  • 打赏
  • 举报
回复
setInterval(a, 1000);
CalvinDo 2010-02-05
  • 打赏
  • 举报
回复
不好意思。。LZ 看错函数。
wtcsy 2010-02-05
  • 打赏
  • 举报
回复
同5L
test
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<input value="xxxxx" onclick="ss()" type="button" />
<input value="xxxxx" onclick="xx()" type="button" />
<script>
function ss(){
alert('a');
};
function xx(){
document.write('1212');
}
</script>
</body>
</html>
2010-02-05
  • 打赏
  • 举报
回复

document.write(s);

因为你用了document.write ,会把当前文档清空,代码也就没了,就不会再执行下去了。
foolbirdflyfirst 2010-02-05
  • 打赏
  • 举报
回复
do not use document.write
  • 打赏
  • 举报
回复
看资料说,
setInterval 是每隔这个时间就执行一次,所以不需要放在里面进行递归的;
setTimeout 才是仅仅只执行一次,是需要放到里面进行递归的。


为什么我这里,setInterval 也仅仅只能执行一次啊
CalvinDo 2010-02-05
  • 打赏
  • 举报
回复

function a() {
var myDate = new Date();
var s = myDate.getSeconds();
document.write(s);
setInterval('a();', 1000);

}

CalvinDo 2010-02-05
  • 打赏
  • 举报
回复
放到a()里面
浴火_凤凰 2010-02-05
  • 打赏
  • 举报
回复
执行一次以后,楼主查看一下源文件就明白了
antony1029 2010-02-05
  • 打赏
  • 举报
回复
document.write(s);
这句有问题,第一次执行完后这句已经将文档刷新了,里面的脚本也不存在了
正确的
Objector 2010-02-05
  • 打赏
  • 举报
回复
document.write(s);
这句有问题,第一次执行完后这句已经将文档刷新了,里面的脚本也不存在了
animshuod521 2010-02-05
  • 打赏
  • 举报
回复
<script language="javascript">
function a() {
var myDate = new Date();
var s = myDate.getSeconds();
document.write(s);
}
setInterval('a()', 1000);
</script>
这样应该是可以的哦
hao_ljp 2010-02-05
  • 打赏
  • 举报
回复
因为你用了document.write ,会把当前文档清空,代码也就没了,就不会再执行下去了。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧