Presumably everyone will write a JavaScript clock code, I will write a small example today:
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "Utf-8"> <title>Small instances of JavaScript clocks</title><style>Div{width:200px;Height:100px;Border-radius:50px;Background-color:Pink; }P{Font-weight:Bolder;Color:Purple;text-align:Center;position:relative;Top:40px; }</style><Script>window.onload= functionmyFunction () {var Time=document.getElementById (" Time"); varN=NewDate (); Time.innerhtml=n.tolocaletimestring (); SetTimeout (MyFunction, +);};</Script> </Head> <Body> <Div> <PID= "Time"></P> </Div> </Body></HTML>
You see the JavaScript code block, I'll explain.
window.onload//run the JS code after the page is loaded.
var n=new Date (); Create a new date
N.tolocaletimestring ();//convert date to String
SetTimeout (myfunction,1000);//Every 1000 milliseconds = 1 seconds run the code in the myFunction () function once
function myFunction () {return 5;} var a=myFunctionvar b=myFunction ();d ocument.write (a);d ocument.write (b); // You can try the above code, a and B are different
JavaScript Clock Code Small analysis