Javascript 返回的图像宽度和高度为零

Javascript 返回的图像宽度和高度为零,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我使用javascript从文件夹中获取所有图像。我按照此链接中的说明进行操作。 但是当我尝试获取图像长度和geight时,它返回0 这是我的密码 window.onload = function() { var dir = "images/"; var fileextension = ".jpg"; $.ajax({ //This will retrieve the contents of the folder if the folder is configured as 'bro

我使用javascript从文件夹中获取所有图像。我按照此链接中的说明进行操作。

但是当我尝试获取图像长度和geight时,它返回0 这是我的密码

window.onload = function() { 
var dir = "images/";
var fileextension = ".jpg";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: dir,
    success: function (data) {
        //Lsit all png file names in the page
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location, "").replace("http:///", "");
            $("#gall").append($("<img src=" + dir + filename + "></img><span>Picture description</span>"));
            this.length;
        });
                pgal.display(); 
    }
});

}
window.onload=function(){
var dir=“images/”;
var fileextension=“.jpg”;
$.ajax({
//如果文件夹配置为“可浏览”,则将检索该文件夹的内容
网址:dir,
成功:功能(数据){
//Lsit页面中的所有png文件名
$(数据)。查找(“a:包含(+fileextension+))。每个(函数(){
var filename=this.href.replace(window.location,“”)。replace(“http:///”,“”);
$(“#gall”)。追加($(“图片说明”);
这是长度;
});
pgal.display();
}
});
}

pgal.display()中,我只是将宽度和高度写入控制台。

您需要这样的内容:

$("#gall").find('img').on('load', function(event) { console.log(event.target) });

您可能需要等待图像加载完成
指的是什么?@manasson我该怎么做?@sheldoncooper此链接可能会有所帮助。我使用了这个,这是控制台上的输出。看起来像是设置了
样式
属性外部删除宽度和高度属性并读取offsetWidth和OffsetHeight结果仍然相同。然后使用
新图像
方法预加载图像