e without the image name. This is because the onLoad handler for an object created with the Image constructor must be the name of a function, and it cannot specify parameters for the displayAlert function.
<SCRIPT> imageA = new Image(50,50) imageA.onload=displayAlert imageA.src="cyanball.gif" function displayAlert(theImage) { if (theImage==null) { alert(''An image loaded'') } else alert(theImage.name + '' has been loaded.'') } </SCRIPT> <IMG NAME="imageB" SRC="greenball.gif" ALIGN="top" onLoad=displayAlert(this)><BR> 示例 3: Looping GIF animation. The following example displays an image, birdie.gif, that is a looping GIF animation. The onLoad事件适用对象the image increments the variable cycles, which keeps track of the number of times the animation has looped. To see the value of cycles, the user clicks the button labeled Count Loops.
<SCRIPT> var cycles=0 </SCRIPT> <IMG ALIGN="top" SRC="birdie.gif" BORDER=0 onLoad="++cycles"> <INPUT TYPE="button" VALUE="Count Loops" onClick="alert(''The animation has looped '' + cycles + '' times.'')"> 示例 4: Change GIF animation displayed. The following example uses an onLoad event handler to rotate the display of six GIF animations. Each animation is displayed in sequence in one Image object. When the document loads, !anim0.html is displayed. When that animation completes, the onLoad event handler causes the next file, !anim1.html, to load in place of the first file. After the last animation, !anim5.html, completes, the first file is again displayed. Notice that the changeAnimation function does not call itself after changing the src property of the Image object. This is because when the src property changes, the image''s onLoad event handler is triggered |