jQuery-如何获取外部图像大小

jQuery-如何获取外部图像大小,jquery,Jquery,我正在生成循环中img标记的列表: @for (int i = 0; i < length; i++) { <img class='my-mimg' alt='' src='https://drive.google.com/uc?export=view&id=someDynamicID' style='max-width : 700px; max-height : 700px;' /> } 但我得到的值为0。那么如何获得该大小?您必须等待图像加载后才能获得其大

我正在生成循环中img标记的列表:

@for (int i = 0; i < length; i++)
{
   <img class='my-mimg' alt='' src='https://drive.google.com/uc?export=view&id=someDynamicID'  style='max-width : 700px; max-height : 700px;' />
}

但我得到的值为0。那么如何获得该大小?

您必须等待图像加载后才能获得其大小

$('img.my-mimg:eq(0)').on('load', function() {
    var width = $(this).css('width');
}).each(function() {
    if (this.complete) $(this).load(); // Fixes caching issues in IE
});
$('img.my-mimg:eq(0)').on('load', function() {
    var width = $(this).css('width');
}).each(function() {
    if (this.complete) $(this).load(); // Fixes caching issues in IE
});