我的多维数组遇到了麻烦。没有错误,但图像没有出现。我不知道为什么。请帮忙
<!doctype html>
<html>
<head><script src="kinetic.js"></script></head>
<body>
<div id="canvas" align="center">
<span id="timer"></span>
<div id="container"></div>
<script>
var stage = new Kinetic.Stage({
container: 'container',
width: 850,
height: 650
});
var layer = new Kinetic.Layer();
var image = [];
var img = [];
var images = [
["1.png","2.png","3.png","4.png"]
];
这是我遇到问题的部分:
for (var a = 0; a < 4; a++) {
img[a] = new Image();
img.src = images[0][a];
img.onload = function(){
image[a] = new Kinetic.Image({
x: Math.floor(Math.random()*400),
y: Math.floor(Math.random()*400),
image: img[a],
width: 500,
height: 500
});
layer.add(image[a]);
image[a].draw();
}
}
</script>
</body>
</html>