这里是一个函数的片段。我得到每个图像的原始大小。然后我想做一个简单的if语句,但不能访问变量'imageWidth'。在'theImage.onload = function()'之外获得'undefined'。它是如何超出范围的?从加载函数访问变量
var parentWidth = $('figure.pack_image').width();
var screenImage = $('figure.pack_image img');
var imageWidth = '';
screenImage.each(function() {
var theImage = new Image();
theImage.src = $(this).attr('src');
theImage.onload = function() {
imageWidth = this.width;
}
if (imageWidth > parentWidth) {
...
异步回调..再次... – gdoron