我有一个图像库,我想给所有的图像标签分配一个类名,在加载完之前显示preload.gif,当图像加载完成后,显示图像。我尝试使用以下代码:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Image loaded: " + document.getElementsById("myImg").complete);
}
</script>
</head>
<body onload="myFunction()">
<p>This property returns true if the image is finished loaded, and false if not.</p>
<img class="myImg" src="compman.gif" alt="Computerman" width="107" height="98">
</body>
</html>
这段代码支持使用id名称,但我希望给所有的图片标签分配类名。