11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<br />

<strong>The</strong> result of a click is shown in Figure 11-3.<br />

Figure 11-3: Contextual information is passed in through the Event object.<br />

Keyboard Events<br />

Surprisingly, DOM Level 2 does not define keyboard events. <strong>The</strong>y will be specified in a future<br />

standard, the genesis of which you can see in DOM Level 3. Fortunately, because (X)HTML<br />

allows keyup, keydown, and keypress events for many elements, you‘ll find that browsers<br />

support them. Furthermore, with IE dominating the picture, you still have that event model to fall<br />

back on. Table 11-13 lists the keyboard-related events for DOM2-compliant browsers, as well<br />

as their behaviors.<br />

Table 11-13: Keyboard Events Supported by Most Browsers<br />

Event Bubbles? Cancelable?<br />

keyup Yes Yes<br />

keydown Yes Yes<br />

keypress Yes Yes<br />

<strong>The</strong> Mozilla-specific key-related properties of the Event object are listed in Table 11-14.<br />

Table 11-14: Additional Properties of the Event Object for Key-Related Events in<br />

Mozilla<br />

Property Description<br />

>altKey Boolean indicating if the ALT key was depressed<br />

>charCode For printable characters, a numeric value indicating the Unicode<br />

value of the key depressed<br />

>ctrlKey Boolean indicating if the CTRL key was depressed during event<br />

>isChar Boolean indicating whether the keypress produced a character<br />

(useful because some key sequences such as CTRL-ALT do not)<br />

>keyCode For non-printable characters, a numeric value indicating the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!