请大侠帮忙看看哪里出问题?老是报错:”缺少对象“

alan_1 2009-09-19 07:02:47
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">

function disptime(){
var now=new Date();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
document.write("<h2>当前时间:"+hour+":"+minute+":"+second);
var time=setTimeout("disptime()",1000);
}

</script>
</head>
<body onload="disptime()">
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>
...全文
95 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
浴火_凤凰 2009-09-20
  • 打赏
  • 举报
回复
清除setTimeout定时器
alan_1 2009-09-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chen_ya_ping 的回复:]
JScript code
window.onload=function() {
window.setInterval("disptime()",1000)
}function disptime() {var now=new Date();var hour= now.getHours();var minute= now.getMinutes();var second= now.getSeconds();
document.write(" <h2>当前时间:"+ hour+":"+ minute+":"+ second);

}
还有你的document.write只能写入一次,换成div来显示时间
[/Quote]
window.onload=function() {
window.setInterval("disptime()",1000)
}:这个不会;
hookee 2009-09-19
  • 打赏
  • 举报
回复
清除setTimeout定时器
chen_ya_ping 2009-09-19
  • 打赏
  • 举报
回复

window.onload = function() {
window.setInterval("disptime()",1000)
}
function disptime() {
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
document.write(" <h2>当前时间:" + hour + ":" + minute + ":" + second);

}

还有你的document.write只能写入一次,换成div来显示时间
alan_1 2009-09-19
  • 打赏
  • 举报
回复
谢了!clearTimeout(time);这是干吗的?
hookee 2009-09-19
  • 打赏
  • 举报
回复

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page </title>
<script language="javascript">
var time;
function disptime(){
var now=new Date();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
document.getElementById("pad").innerHTML = "当前时间:"+hour+":"+minute+":"+second;
clearTimeout(time);
time=setTimeout("disptime()",1000);
}

</script>
</head>
<body onload="disptime()">
<form id="form1" runat="server">
<div id="pad">

</div>
</form>
</body>
</html>

87,922

社区成员

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

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