This is a very simple example of what a few lines of code can do after JavaScript,
But for some people who have not been in touch with JavaScript, almost a big project, and then on the Internet to search for code, and then in the vast HTML code to seek, and ultimately do not have the essentials.
I. BASIC OBJECTIVES
Implement a Web page text time that accompanies the client (on the browser machine), using the shortest code.
Second, the production process
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
1.Date Object If you use a constructor that has no parameters, the time is returned to the client, and the toLocaleString () method is to convert the time to a local display time format, and if only the ToString () method only converts the time into a time string of English notation. At the same time, personally realize the Discovery toLocaleTimeString () method is not present, please do not toss. If you are not satisfied with the time the system comes in, use the various methods of Getday (), GetMonth (), getFullYear () to construct the string. Not to show again.
The 2.innerHTML corresponds to all the elements under the clock, document.getElementById ("clock"). InnerHTML = time; The meaning of a sentence <span id= "Clock" > The contents of the </span> two tag changed to the time string
3. The key to this JavaScript is the setinterval ("clock ()", 1000) function, which means every 1000 milliseconds, that is, every 1 seconds, the clock () function is executed once. That is, every second, updates the contents of the <span id= "clock" ></span> two tag into a time string.
"JavaScript" a dynamic time synchronized to local time