JavaScript 超简单问题 速度来 我好结贴

wenjunsu 2010-09-02 11:24:53

<html>

<head>
<script type="text/javascript">
function show()
{
var time=new Date();
var hour=time.getHours();
var minute=time.getMinutes();
var second=time.getSeconds();
document.write(hour+":"+minute+":"+second);
setTimeout("show()",1000);
}
</script>
</head>

<body>
<input type="button" value="点击开始时间" onClick="show()"/>

</body>

</html>



我想让他一直动态显示时间 为什么不可以?
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lchy110 2010-09-02
  • 打赏
  • 举报
回复
孟子E章 讲的很对 学习了。。。
孟子E章 2010-09-02
  • 打赏
  • 举报
回复
document.write会把当前页面的所有变量清除
孟子E章 2010-09-02
  • 打赏
  • 举报
回复
Do not use the write method or the writeln method on the current document after the document has finished loading unless you first call the open method, which clears the current document window and erases all variables.
wenjunsu 2010-09-02
  • 打赏
  • 举报
回复
为什么 只会执行一次
setTimeout 不是在嘛??
avengercf 2010-09-02
  • 打赏
  • 举报
回复
因为程序只会执行一次。
孟子E章 2010-09-02
  • 打赏
  • 举报
回复
<html>

<head>
<script type="text/javascript">
function show()
{
var time=new Date();
var hour=time.getHours();
var minute=time.getMinutes();
var second=time.getSeconds();
document.getElementById("x").innerHTML=(hour+":"+minute+":"+second);
setTimeout("show()",1000);
}
</script>
</head>

<body>
<input type="button" value="点击开始时间" onClick="show()"/>
<div id=x></div>
</body>

</html>

87,910

社区成员

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

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