2007woaini 发表于 2008-5-20 20:33

菜鸟求助:表单不显示时间!!!!

奥运会倒计时(Math.floor()取整)
要求:(1)显示“距离奥运会还有:?天?时?分?秒”
(2)每隔1秒自动更新一次
提示:利用Date( )的方法以及Math.floor( )(向下取整)
<html>
     <head>
          <title>奥运会倒计时</title>
      </head>
      <script language="javascript">
            <!--
                var future=new Date("8/8/2008,20:08:08");
                var time
                function hello(){
                var tody=new Date();
                var day=Math.floor(hours/24);
                var hours=Math.floor(minutes/60);
                var minutes=Math.floor(senconds/60);
                var seconds =Math.floor((future.getTime()-tody.getTime())/1000);
                var timer=setTimeout("hello()",1000);
                document.clock.text1.value=day;
                document.clock.text2.value=hours;
                document.clock.text3.value=minutes;
                document.clock.text4.value=seconds;
                }
            -->
       </script>
       <body>
            <form name=clock>
                  <center>
                  <font size=5 color=lightblue>距离奥运会还有</font><br>
                  <input type="text"name="text1" size="5"> 天
                  <input type="text"name="text2" size="5"> 时            
                  <input type="text"name="text3" size="5"> 分
                  <input type="text"name="text4" size="5"> 秒
                  </center>
      </body>
</html>

hwoarangzk 发表于 2008-5-21 09:19

因为你的script代码放在了body前面,form还没有加载好,怎么能找到呢?可以把你的这些script放在一个函数里面,然后通过body的onload来调用就可以了

hwoarangzk 发表于 2008-5-21 09:32

LZ的代码还有很多问题,form没有结束标志,seconds,minutes,hours这些定义的先后顺序有问题,,form、input里面的属性值最好用引号括起来,setTime不要放在hello里面

polish_tsingji 发表于 2008-5-21 12:36

能把正确的代码写出来吗?
谢谢!

polish_tsingji 发表于 2008-5-21 12:37

求助

能把正确的代码写出来吗?
谢谢!

hwoarangzk 发表于 2008-5-21 13:10

<html>
     <head>
          <title>aaa</title>
      </head>
      <script language="javascript">

                var future=new Date("8/8/2008,20:08:08");
                var time;
                function hello(){
                        var tody=new Date();
                        var seconds =Math.floor((future.getTime()-tody.getTime())/1000);
                        var minutes=Math.floor(seconds/60);
                        var hours=Math.floor(minutes/60);
                        var day=Math.floor(hours/24);
                        var timer=setTimeout("hello()",1000);
                        document.clock.text1.value=day;
                       document.clock.text2.value=hours;
                        document.clock.text3.value=minutes;
                }

       </script>
       <body onload="hello();">
            <form name="clock">
                  <center>
                  <font size=5 color="lightblue">still</font><br>
                  <input type="text" name="text1" size="5">Day
                  <input type="text" name="text2" size="5"> H            
                  <input type="text" name="text3" size="5"> M
                  </center>
            </form>
      </body>
</html>
我电脑不支持中文,而且把seconds删了,自己改回来吧

polish_tsingji 发表于 2008-5-21 16:40

为什么秒跟现实走的速度不一样?

polish_tsingji 发表于 2008-5-21 16:45

解决了

2007woaini 发表于 2008-6-5 21:08

还是不行呢!!!

随风逐流 发表于 2008-6-6 16:53

我強烈要求頂這個帖子!!!!!!!!!!!!!!!
現在有人把代碼寫的這么規範的人已經很難找了

FFEEDD 发表于 2008-6-6 21:08

呵呵```的确如此啊``
新手都这样
比如我```

页: [1]

编程论坛