JavaScript Clock Code Small analysis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.