今天是

爱酷家


当前位置:首页 > 资源收藏 > 特效代码

JavaScript 实现的简单时钟

收集整理   发布时间:2015-03-17 20:23:00   阅读

JavaScript 实现的简单时钟

(1)在〈Head〉〈/Head〉之间放置以下脚本:
  <script language="JavaScript">
   <!--
   var timerID = null;
   var timerRunning = false;
   var id,pause=0,position=0;
   function stopclock ()
   { if(timerRunning)
   clearTimeout(timerID);
   timerRunning = false;
   }
   function showtime ()
   {
   var now = new Date();
   var hours = now.getHours();
   var minutes = now.getMinutes();
   var seconds = now.getSeconds()
   var timeValue = "" + ((hours >12) ? hours -12 :hours)
   timeValue += ((minutes < 10) ? ":0" : ":") + minutes
   timeValue += ((seconds < 10) ? ":0" : ":") + seconds
   timeValue += (hours >= 12) ? " P.M." : " A.M."
   document.clock.face.value = timeValue;
   timerID = setTimeout("showtime()",1000);
   timerRunning = true;
   }
   function startclock ()
   { stopclock();
   showtime(); 
   }
   //-->
   </script>
  (2)在〈Body〉属性中加 onLoad="startclock()"
   (3)在〈Body〉〈/Body〉中间加
  <form name="clock" onSubmit="0">
   <div align="center">
   <center><p><input type="text" name="face" size="13" value></p></center>
   </div>
   </form>
  即可。

 



注:⊙如转载本站原创作品,请务必包保留本文地址:

内容: