15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

100<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Example<br />

The onClick event handler is one of the simplest to grasp and use. Listing 15-35<br />

demonstrates its interaction with the onDblClick event handler and shows you<br />

how to prevent a link’s intrinsic action from activating when combined with click<br />

events. As you click and/or double-click the link, the status bar displays a message<br />

associated with each event. Notice that if you double-click, the click event fires<br />

first with the first message immediately replaced by the second. For demonstration<br />

purposes, I show both backward-compatible ways of cancelling the link’s intrinsic<br />

action. In practice, decide on one style and stick with it.<br />

Listing 15-35: Using onClick and onDblClick Event Handlers<br />

<br />

<br />

onClick and onDblClick Event Handlers<br />

<br />

var msg = “”<br />

function showClick() {<br />

msg = “The element has been clicked. “<br />

status = msg<br />

}<br />

function showDblClick() {<br />

msg = “The element has been double-clicked.”<br />

status = msg<br />

return false<br />

}<br />

<br />

<br />

<br />

onClick and onDblClick Event Handlers<br />

<br />

<br />

A sample link.<br />

<br />

<br />

onContextMenu<br />

elementObject.onContextMenu<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓

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

Saved successfully!

Ooh no, something went wrong!