用JS做个网页记时器~

来源:百度知道 编辑:UC知道 时间:2024/06/07 10:56:25
页面打开后开始累计时间:你在此已逗留:0时0分0秒
!不使用if语句啊!
下面的代码哪里错了呀?如何改进?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>记时</title>
<script language="javascript">
var sec=0;
var time=new Date();
time.setSeconds(0);
time.setMinutes(0);
time.setHours(0);
function update()
{
document.myform.myclock.value="您在此逗留的时间为:"+time.getHours()+"时"+
time.getMinutes()+"分"+time.getSeconds()+"秒";
time.setSeconds(sec++);
setTimeout("update();",1000);
}
</script>
</head>

<body onLoad="update()">
<form name="myform">
<input type="text" name="myclock" size="30">
</form>
</body>
</html>
谢谢了~

这么简单的问题都没有人回答??汗...
我自己回答吧~今天刚做出来~就是不用IF做的~嘎嘎!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
var time=new Date();
time.setHours(0);
time.setMinutes(0);
time.setSeconds(0);
function myfun()
{
var sec=time.getSeconds();
document.myform.myclock.value="您在此逗留的时间为:"+time.getHours()+"时"+time.getMinutes()+"分"
+time.getSeconds()+"秒";
time.setSeconds(sec+1);
setTimeout("myfun()",1000);
}
</script>
</head>
<body onLoad="myfun()">
<form name="myform">
<input name="myclock" type="text" size="25">
</form>
</body>
</html>