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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{<br />

}<br />

if (document.images)<br />

document[imgName].src = eval(imgName + "on.src");<br />

// On input "myimage" this function sets the src of the image with<br />

// this name to the value of myimageoff.src<br />

function mouseOff(imgName)<br />

{<br />

}<br />

if (document.images)<br />

//-->><br />

document[imgName].src = eval(imgName + "off.src");<br />

<br />

Notice how we generalized not only the image swapping function, but also the preloading<br />

functionality.<br />

Later on, somewhere in our HTML file we would have appropriately named the images and<br />

links with onmouseover and onmouseout handlers to trigger the appropriate parts of the<br />

script:<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!