如何访问 的值imgWidth?这是给我undefined的。
somejQueryMethod(function() {
var imgWidth;
$("<img/>").attr(
"src",
$("#SomeImgSelector").attr("src")
).load(function() {
imgWidth = this.width;
});
// use imgWidth here
// imgWidth is undefined here
});
背景信息:从这个 SO question我假设,正如在方法
imgWidth之外定义的那样load(),它总是可以在load(). 这让我想知道为什么定义imageWidththere 而不是 inload()?