1. 程式人生 > >JS時鐘

JS時鐘

brush tar var ati select doc lec ets gets

<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById(‘txt‘).innerHTML=h+":"+m+":"+s
t=setTimeout(‘startTime()‘,500)
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>

  setTimeout(function,n)表示的是在n毫秒之後執行function這個方法或者是代碼。技術分享

JS時鐘