HTML and CSS Reference
In-Depth Information
Table G-8 JavaScript Statements (continued)
Statement
Description
for each...in
Iterates a specified variable through object property line arrays and array-like objects (Gecko
engine only).
function
Defines a new function. Acceptable parameters include strings, numbers, and objects.
For example, function myfunc( ) {.
if...else
Executes one block of statements if the condition is true. Executes another block of statements
if the condition is false.
label
Provides an identifier that can be used with break or continue to indicate where the program
should continue execution.
let
Initializes a local variable in a block.
return
Causes the current function to halt and possibly returns a value to the caller. For example, return
endingval.
switch
Allows a program to evaluate an expression and attempts to match the expression's value to a
case label.
throw
Throws or sends an exception. The exception can be an expression or an object.
try...catch
Executes a block of statements to try, and the statements to execute if an error occurs.
Implemented in Internet Explorer 5 and later.
var
Declares and possibly initializes new variables. For example, var retval.
while
Creates a loop that evaluates an expression, and if it is true, executes a block of statements. The
loop then repeats, as long as the specified condition is true.
with
Establishes the default object for a block of statements.
Event Handlers
JavaScript makes HTML documents dynamic through events. An event is an action that
a user makes, such as clicking a button. Usually, when an event occurs, JavaScript code
executes. Event handler names always begin with “on.” In standard HTML, event handler
names are in mixed case; the first letter after the word “on” is in uppercase. In XML and
XHTML, because all attributes must be in lowercase, they are spelled in all lowercase
characters. Table G-9 summarizes the JavaScript event handlers.
Table G-9 Event Handlers
Event Handler
Triggered When
Handler For
Used in HTML Statement
onabort
The loading of an image
is interrupted
Image
<img>
onafterprint
After page has printed
Window (Internet
Explorer only)
<body>
onbeforeprint
Fires just before a page is
printed or examined for
Print Preview
Window (Internet
Explorer only)
<body>
onbeforeunload
Displays message
just before a page is
unloaded
Window
<iframe>
onblur
An element becomes
inactive
Button, Checkbox,
FileUpload, Layer, Password,
Radio, Reset, Select,
Submit, Text, Textarea,
Window
<body> ... </body>
<frameset> ... </frameset>
<frame> ... </frame>
<input type 5 ”text” />
<textarea> ... </textarea>
<select> ... </select>
onchange
The value of an element
changes
FileUpload, Select, Text,
Textarea
<input type 5 ”text” />
<textarea> ... </textarea>
<select> ... </select>
Search WWH ::




Custom Search