我正在构建一个 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")
}