Javascript jquery回调通过ajax调用加载的新图像
我有一个函数来获取图像的宽度和高度,但它不响应通过ajax调用加载的新图像 该职能是—Javascript jquery回调通过ajax调用加载的新图像,javascript,jquery,onload-event,Javascript,Jquery,Onload Event,我有一个函数来获取图像的宽度和高度,但它不响应通过ajax调用加载的新图像 该职能是— $('img').on('load',function() { console.log(this.width + 'x' + this.height); }); 但是我使用ajax调用将DOM添加到页面中,但是上面的代码没有响应加载的新图像 我的示例页面包含控制台日志 关于你需要这样做 $("img").one("load", function() { }).each(function() {
$('img').on('load',function() {
console.log(this.width + 'x' + this.height);
});
但是我使用ajax调用将DOM添加到页面中,但是上面的代码没有响应加载的新图像
我的示例页面包含控制台日志
关于你需要这样做
$("img").one("load", function() {
}).each(function() {
if(this.complete){
console.log(this.width + 'x' + this.height);
}
});
更新
好吧,这是要做的,正如
当你添加DOM inI时,你必须附加onLoad事件。inI编辑了问题并添加了示例页面我认为@Andy你应该删除标记“问题可能在这里有答案”@PradyutBhattacharya,我不能这样做。不,这没有帮助,我得到0x0你也可以添加你的html部分吗?我已经用示例页面编辑了我的问题。请参阅我的更新答案
$("div.albumList").on("load","img", function() {
console.log(this.width + 'x' + this.height);
});
$.ajax({
type: "POST",
url: 'bAlbum.jsp',
data: null ,
cache: false,
success: function(html){
$('ol#imagelist').append(html);
$("ol#imagelist li").each( function (i, e)
{
$(e).find('img').one('load', function() {
console.log(this.width + 'x' + this.height);
});
});
}
});