home / experts / javascript / column9 |
|
The simplest way to catch an event is the traditional event handler, which was first implemented in Navigator 2.0x and Internet Explorer 3.0x. Simply specify the desired event handler as an attribute of its HTML tag. The following HTML document demonstrates the use of two event handlers in one tag:
This page displays the message "Hello" when you load it, and "Goodbye" when you unload it. Notice that each event handler is a distinct attribute. An event handler script is executed when the corresponding event occurs. In this example, each event handler specifies a single statement:
It's also possible to include several statements in one event handler script by delimiting the statements with semicolons. Here's an example:
As in any other script, you do not need a semicolon after the last statement. In fact, if you place each statement on a separate line, you don't need semicolons at all:
Event handlers are case-insensitive. For example, you can use
Many HTML tags support event handlers. In the previous examples we used the
The output of the preceding code is: |
Created: December 16, 1997
Revised: December 16, 1997
URL: http://www.webreference.com/js/column9/eventhandlers.html