HTML and CSS Reference
In-Depth Information
You have only one function to run for Hector's Web page: the NYClock() function.
Because the function should run once every second, you will use the following com-
mand, which runs the NYClock() function continuously at intervals of 1000 millisec-
onds, or one second:
setInterval(“NYClock()”, 1000)
You will replace the event handler in the <body> tag with this setInterval() method.
The revised event handler is:
onload = “setInterval( ' NYClock() ' , 1000)”
Note that because the contents of the event handler attribute are enclosed in double
quotation marks, you must use single quotation marks to enclose the name of the func-
tion to avoid confusion about which set of quotation marks refers to the onload attribute
and which refers to the function being run.
To run the NYClock() function every second:
1. Return to the clock.htm file in your text editor.
2. Change the attribute of the onload event handler attribute in the <body> tag to
the following, as shown in Figure 11-36:
Figure 11-36
running the nYclock() function every 1000 milliseconds
runs the function every
1000 milliseconds
(once every second)
sets the time interval between
repeats of the NYClock() function
3. Close the file, saving your changes.
4. Reload or reopen clock.htm in your Web browser. The countdown clock appears
one second after the page loads, and both the countdown clock and the current
time update continually as the NYClock() function is run again and again.
Search WWH ::

Custom Search