我正在开发一款JavaScript游戏,想要在所有图像都加载完成后弹出提示。我尝试了以下代码,但它并没有起作用:
function loadEveryThing() {
var imgNumber = 0;
img1 = new Image();
img1.src = "1.png"
img1.onload = function() {
imgNumber = imgNumber + 1;
}
img2 = new Image();
img2.src = "2.png"
img2.onload = function() {
imgNumber = imgNumber + 1;
}
img3 = new Image();
img3.src = "3.png"
img3.onload = function() {
imgNumber = imgNumber + 1;
}
if (imgNumber == 3) alert("done")
}