您可以使用圖像對象的onLoad事件。類似這樣的:
<html>
<head>
<script type="text/javascript">
function imageLoaded(imgId, url) {
alert(imgId);
var img = document.getElementById(imgId);
img.src = url;
}
</script>
</head>
<body>
<img id="bg" src="http://pupunzi.files.wordpress.com/2009/01/imgnav.jpg?w=350&h=285" alt="image" onLoad="imageLoaded('img1', 'http://forbiddenplanet.co.uk/blog/wp-content/uploads/2009/01/Adam%20Elliot%20Max%20and%20Mary%20animation.jpg');" />
<img id="img1" onLoad="imageLoaded('img2', 'http://pupunzi.com/images/components/mb.imageNavigator.png');" alt="image 1" />
<img id="img2" alt="image 2"/>
</body>
</html>
在這個例子中,我讓警報讓你看到如何加載前一圖像時加載圖像。