JavaScript displays the time, and the time is still moving! Not a static effect!
function Time() defines a function.
{ if (!document.layers&&!document.all)
return Because IE and Netscape have different interpretations of JavaScript, resulting in different browsing effects, they need to write codes separately. This sentence determines the browser used by the user, and if it is neither, it returns.
var timer=new Date() defines a new variable named timer, which is a new Date object.
var hours=Timer.getHours()
var minutes=Timer.getMinutes()
var seconds=Timer.getSeconds() Define 3 variables respectively to get the current "hour", "minute", " seconds" value.
var noon="AM" if (hours>12)
{ noon="PM" hours=hours-12 }
if (hours==0)
hours=12 Define a named For the "noon" variable, when the number of "hours" is greater than 12, its value is PM, and the resulting value is subtracted by 12; when the number of "hours" is less than 12, its value is AM.
if (minutes<=9)
minutes="0" minutes
if (seconds<=9)
seconds="0" seconds If the number of "minutes" or "seconds" is less than 9 , add a "0" in front.
myclock="" hours ":" minutes ":" seconds " " noon "" Use a new variable to change "hours, minutes, seconds" Combined.
if (document.layers)
{ document.layers.position.
document.write(myclock)
document.layers.position.document.close() } If the browser is Netscape, then Output myclock, and the code for IE stops executing.
else if (document.all)
position.innerHTML=myclock Otherwise, if the browser is IE, myclock will be output.
setTimeout("Time()",1000) The Time function is called every 1000 milliseconds, that is, it moves once per second.
onload="Time()" When the page is loaded, the Time() function is called.