| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 760 人关注过本帖
标题:setInterval有点问题?
只看楼主 加入收藏
VB爱上我
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:478
专家分:52
注 册:2005-10-14
结帖率:100%
收藏
 问题点数:0 回复次数:1 
setInterval有点问题?

<script language="javascript" type="text/javascript">

function showTime() {var myTime = new Date();
var inHours = myTime.getHours();
if (inHours < 10) {inHours = "0" + inHours}
var inMinutes = myTime.getMinutes();
if (inMinutes < 10) {inMinutes = "0" + inMinutes}
var inSeconds = myTime.getSeconds();
if (inSeconds < 10) {inSeconds ="0" + inSeconds}
document.write("现在的时间是:" + inHours + ":" + inMinutes + ":" + inSeconds)}
list = setInterval(showTime,1000);
</script>

刚开始发现只能显示一次时间,就不动了,原来是因为document.write把源程序给替换了,函数不见了。list = setInterval(showTime,1000);setInterval的机制是怎么样的,难道没有记下来。


[此贴子已经被作者于2007-8-28 9:52:58编辑过]

搜索更多相关主题的帖子: setInterval 
2007-08-27 18:46
VB爱上我
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:478
专家分:52
注 册:2005-10-14
收藏
得分:0 
<script src="new.js" type="text/javascript"></script>
<script>show=setInterval("showTime()",1000);</script>
new.js
function showTime(){var myTime = new Date();
var inHours = myTime.getHours();
if (inHours < 10) {inHours = "0" + inHours}
var inMinutes = myTime.getMinutes();
if (inMinutes < 10) {inMinutes = "0" + inMinutes}
var inSeconds = myTime.getSeconds();
if (inSeconds < 10) {inSeconds ="0" + inSeconds}
clearInterval(show);
location.reload();//如果不要这行,就会出现每秒的时间
document.write('<script src="new.js" type="text/javascript"></script>');
document.write(inHours+":"+inMinutes+":"+inSeconds+"<BR>");
document.write('<script>show=setInterval("showTime()",1000);</script>');
}

IT618资讯网 提供服务端开发,前端开发,网页特效,热门开源系统研究,软件下载,站长建站,淘宝开店等学习资料.
2007-08-28 09:52
快速回复:setInterval有点问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025752 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved