我有一个获取图像宽度和高度的函数,但它不会响应通过ajax调用加载的新图像。
其功能是-
$('img').on('load',function() {
console.log(this.width + 'x' + this.height);
});但是,我使用ajax调用将DOM添加到页面,但是上面的代码不响应正在加载的新图像。
我的示例页面是带有控制台日志的here in the link。
问候
发布于 2014-07-23 19:24:27
好的,就像Rafael Diaz说的那样
$.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);
});
});
}
});https://stackoverflow.com/questions/24908080
复制相似问题