<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
var id,im=0,is=1;
start=new Date();
function go()
{
now =new Date();
time=(now.getTime()-start.getTime())/1000;
time=Math.floor(time);
is=time%60;
im=Math.floor(time/60);
if(is<10)
document.myform.clocks.value=" "+im+" 分 0"+is+"秒";
else
document.myform.clocks.value=" "+im+"分"+is+"秒";
id=setTimeout("go()",1000);
}
go();
</script>
</head><body>
<form name="mytable" id="myform">
<input name="tclocks" id="clocks" type="text" value="" />
</body>
</html>
预览时总是弹出提示---------------------------
错误
---------------------------
出现了运行时间错误。
是否要进行调试?行: 16
错误: 'document.myform.clocks' 为空或不是对象
---------------------------
是(Y)   否(N)   
---------------------------不知道是哪里出问题了?

解决方案 »

  1.   

    name="tclocks" <-- 是tclocks还是 clocks ?
      

  2.   

    <form name="myform" id="myform"> form的name要 myform
      

  3.   


    我现在还不太清楚,document访问form时候还有访问form里的控件的时候用的是name属性的值还是id属性的值?
      

  4.   

    而且我刚才发现无论用name的属性值,还是用ID属性值错误提示都是一样的.
      

  5.   

    还有加载顺序问题<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript" type="text/javascript">
    var id,im=0,is=1;
    start=new Date();
    function go()
    {
        now =new Date();
        time=(now.getTime()-start.getTime())/1000;
        time=Math.floor(time);
        is=time%60;
        im=Math.floor(time/60);
        if(is<10)
        document.myform.clocks.value=" "+im+" 分 0"+is+"秒";
        else
        document.myform.clocks.value=" "+im+"分"+is+"秒";
        id=setTimeout("go()",1000);
    }
    window.onload=function(){
      go();
    }
    </script>
    </head><body>
    <form name="myform">
    <input name="clocks" type="text" value="" />
    </form>
    </body>
    </html>