Javascript小时钟

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">

  <script>
     function tick()
  {
     var hours,minutes,seconds,ap;
  var intHours,intMinutes,intSeconds;
  var today;
  today=new Date();
  intHours=today.getHours();
  intMinutes=today.getMinutes();
  intSeconds=today.getSeconds();
  if(intHours==0)
  {
      hours="12:";
   ap="midnight"
  }else if(intHours<12)
  {
     hours=intHours+":";
     ap="A.M.";
  }else if(intHours==12)
  {
     hours="12:";
     ap=Noon;
  }
  else
  {
     intHours=intHours-12;
     hours=intHours+":";
     ap="P.M."
  }

  if(intMinutes<10)
  {
     minutes="0"+intMinutes+":";
  }else{minutes=intMinutes+":"}

  if(intSeconds<10)
  {
     secondes="0"+intSeconds+":";
  }else{ seconds=intSeconds+":";}
       
  timeString=hours+minutes+seconds+ap;
  Clock.innerHTML=timeString;

  window.setTimeout("tick();",100);

  
       }
      window.onload=tick;
  </script>
 </HEAD>

 <BODY>
     <h1>改變頁面樣式</h1>
  <div id="Clock" align="center"></div>
  <table border="1">
      <tr>
      <td>時鐘顏色</td>
            <td>時鐘背景</td>
   <td>時鐘字體</td>
   <td>時鐘尺寸</td>
   <td>時鐘粗細</td>
   </tr>
         <tr>
      <td cospan="5"></td>
   </tr>
   <tr>
      <td><span onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="Clock.style.color='purple'">紫色</span></td>
   <td><span onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="Clock.style.color='red'">紅色</span></td>
   <td><span onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="Clock.style.fontFamily='verdana'">無邊師</span></td>
   <td><span onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="Clock.style.fontSize='24pt'">24pt</span></td>
   <td><span onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="Clock.style.fontWeight='normal'">普通</span></td>
   </tr>
   <tr>
      <td><span>白色</span></td>
   <td><span>黃色</span></td>
   <td><span>有邊師</span></td>
   <td><span>36pt</span></td>
   <td><span>粗體</span></td>
   </tr>
  </table>
 </BODY>
</HTML>

 

 

总结:   1.在整个Document中某个标签下的事件可以直接使用ID取整个Document的任何标签.


posted @ 2008-12-04 15:54  XGU_Winner  阅读(222)  评论(0编辑  收藏  举报