Warning: session_start() [function.session-start]: open(/home/mybwtech/public_html/article/tmp/sess_9a6ccc0045a7df4ba1a4bf7741727eb6, O_RDWR) failed: No such file or directory (2) in /home/mybwtech/public_html/article/global.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/mybwtech/public_html/article/global.php:3) in /home/mybwtech/public_html/article/global.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mybwtech/public_html/article/global.php:3) in /home/mybwtech/public_html/article/global.php on line 3
JavaScript时间显示三大心法 - 龙舞天翔资源共享
我的控制台 会员登陆 免费注册 最后更新 高级搜索 返回首页 我要投稿 退出登陆 龙舞论坛
当前在线: 0
 
站内搜索
Google
www.bwtech.net

德州扑克资料
投资透视
网站优化推广&SEO
网站设计
网络编程语言与开发
课件开发制作
网络文学
小资生活
数码摄影
财经-经营管理
其他杂项
龙舞天翔资源共享 / 网站设计 / JAVA SCRIPT / JavaScript时间显示三大心法
JavaScript时间显示三大心法
2006-06-07       互联网    点击: 1463
JavaScript时间显示三大心法

      JAVASCRIPT的妙用
      前几天,我的一位朋友问我:“你的个人主页中有一个动态时间表,我很是喜欢。不知你是如何制作出来的?大概用了很复杂的程序吧!”“你过奖了,其实这个显示时间的程序非常简单,只要你记住我以下的三大心法,我保证你的主页也会绚丽多姿起来。”我自豪地笑道。

      心法一:在网页中调用时间。
      心法口诀如下:<script language="javascript">
      function time_rota()
      {
      now = new Date();
      h="0"+now.getHours();
      m="0"+now.getMinutes();
      s="0"+now.getSeconds();
      if(h>9){h=now.getHours()}
      if(m>9){m=now.getMinutes()}
      if(s>9){s=now.getSeconds()}
      document.write(" "+h+":"+m+":"+s+" ");
      }
      </script>
      <script>
      time_rota()
      </script>


      心法口诀重要部分说明:
      
      一.参数“0”。若不加此参数的话,时间表显示的时间只是单位,例如,在凌晨1点零1分零1秒时显示:“1:1:1”。是不是很难看啊!加了参数“0”后我们再看一下:“01:01:01”,变成了双位显示时间,漂亮了吧!
      二.“if”语句。这语句运用主要是为了正确显示双位时间,若不用此语句的话当“时,分,秒”无论哪一个超过10以后都会显示三位数字,例如:在12点12分12秒时显示:“012:012:012”,太夸张了!因此“if”语句一定要在程序中使用。

      另外,在网页中调用时间程序也可以简化为:(但是若您学过编程语言的话,您一定知道上面的程序要比下面的程序严谨得多,且下面的程序不能正确显示双位时间。)
      <script language="javascript">
      today=new Date();
      document.write(today.getHours()+":",today.getMinutes()+":",today.getSeconds());
      </script>

      
      心法二:网页动态时间表。

      心法口诀如下:
      <script>
      function time_rota()
      {
      now = new Date();
      h="0"+now.getHours();
      m="0"+now.getMinutes();
      s="0"+now.getSeconds();
      if(h>9){h=now.getHours()}
      if(m>9){m=now.getMinutes()}
      if(s>9){s=now.getSeconds()}
      document.Time.CLOCK.value =" "+h+":"+m+":"+s+"       "
      setTimeout( 'time_rota()', 1000)
      }
      </script>
      <table>
      <tr>
      <td><form method="post" name="Time">
      <p><input name="CLOCK" size="12" value="显示时间">       </p>
      </form>
      </td>
      <script>
      time_rota()
      </script>


      心法口诀重要部分说明:

      一.document.Time.CLOCK.value中的“Time、CLOCK”分别对应表单中“name,input name”后定义的名字。因此此两部分内容必须相同,否则此程序肯定无效。
      二.setTimeout('time_rota()',1000)表示指定程序每秒运行一次,也就是动态计时。


      心法三:状态条上的动态显示时间。
      心法口诀如下:
      <script language="javascript">
      function time_rota()
      {
      now = new Date();
      h="0"+now.getHours();
      m="0"+now.getMinutes();
      s="0"+now.getSeconds();
      if(h>9){h=now.getHours()}
      if(m>9){m=now.getMinutes()}
      if(s>9){s=now.getSeconds()}
      setTimeout( "time_rota()",1000);
      window.status=" "+h+":"+m+":"+s+" ";
      }
      </script>
      <script>
      time_rota()
      </script>
      心法口诀重要部分说明:
      此心法是从以上两则心法中引伸而出,心法大意与上面相同。只是要学会使用window.status这一功能,它的作用是把文字显示在状态条上。
      “好了心法就讲到这里,我的朋友现在你的感觉如何,是不是跃跃欲试啦!”我望着他问道。“我记住了,谢谢!”他欣喜若狂……
      今天,我的那位朋友邀我去他的主页上作客,他说会给我一份意外的惊喜。于是,我便上了他的主页,原来他也用上的动态时间表并且在他的网页中向我表示了崇高的敬意同时称我是“高手”。
      “‘高手’下一步你该做什么?对了写文章,把此三大心法与网民们共享。”我自言自语道。 

责任编辑: 龙舞天翔

相关文章
JavaScript窗口功能指南之关闭窗口 - 06-04 10:37 am - 点击: 437
javascript 时间脚本收集 - 06-04 10:10 am - 点击: 404
javascript停留时间代码 - 06-04 10:08 am - 点击: 540

发表评论 查看评论 加入收藏 Email给朋友 打印本文
如果你想对该文章评分, 请先登陆, 如果你仍未注册,请点击注册链接注册成为本站会员.
平均得分 0, 共 0 人评分
1 2 3 4 5 6 7 8 9 10
Copyright © 2002 -2003 龙舞天翔资源共享
All rights reserved.
Powered by: phpArticle Version 2.0

Warning: Unknown: open(/home/mybwtech/public_html/article/tmp/sess_9a6ccc0045a7df4ba1a4bf7741727eb6, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/home/mybwtech/public_html/article/tmp) in Unknown on line 0