どういうわけか、私のカウンター変数は子関数に渡されません。非同期の振る舞いが原因だと思いますが、実際には手がかりがありません。助けてください。
$(document).ready(function() {
var imgArray = new Array();
$("canvas").each(function(i) {
imgArray[i] = new Image();
});
$.each(imgArray, function(i) {
alert(i);
//correct output
this.onload = function() {
alert(i);
//"undefined"
var width = this.width,
height = this.height;
var context = $("canvas")[i].getContext("2d");
//here's the error
/* more code */
};
this.src = "PATH";
});
});
では、どのようにして適切なキャンバスの値を渡すことができますか?
助けてくれてありがとう!