【发布时间】:2012-10-19 18:50:45
【问题描述】:
这里是一个函数的 sn-p。我正在获取每个图像的原始大小。然后我想做一个简单的 if 语句,但不能访问变量'imageWidth'。在“theImage.onload = function()”之外获取“未定义”。怎么会超出范围?
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) {
...
【问题讨论】:
标签: jquery function variables scope global