Let’s see some examples using images and JavaScript. The most basic type of image work is where you just swap images using the src property; here’s an example where the image displays when the page loads displays the text Image 1; but when you click a button, the code loads a new image, which displays Image 2:
Code View:
Scroll
/
Show All <HTML> <HEAD> <TITLE> Reloading Images </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function newImage() { document.form1.img1.src = "image2.jpg" } //--> </SCRIPT> </HEAD> <BODY> <H1>Reloading Images</H1> <FORM NAME="form1"> <IMG NAME="img1" SRC="image1.jpg" WIDTH="216" HEIGHT="72"> <BR> <INPUT TYPE="BUTTON" Value="Load new image" ONCLICK="newImage()"> </FORM> </BODY> </HTML> |