所以我想读取通过jQuery创建的img元素的高度和宽度。页面加载和页面刷新的价值差异
这是我试图执行
$(document).ready(function()
{
$.ajax({
url: 'res/script/getImage.php',
type: 'POST',
data: {
param : 'Load'
},
success: function(result)
{
ImageArray = JSON.parse(result);
for(i=0; i<ImageArray.length; i++)
{
//Read the Image element and update to gallery
document.getElementById("gallery").innerHTML += ImageElement;
ImageArrayComplete[ImageCounter] = ImageArray[i].image;
UserArrayComplete[ImageCounter] = ImageArray[i].user;
}
//Create Canvas
$('#gallery img').each(function() {
console.log(this);
console.log('Width=' + this.width+ 'Height='+this.height);
createCanvas(this);
});
}
});
});
的console.log(this);
输出为图像,其是如预期的路径的代码。
但在初始页面加载期间,对于宽度和高度,console.log('Width=' + this.width+ 'Height='+this.height);
的输出均为0。
一旦刷新页面,该值将重置为实际宽度200。
没有其他错误抛出并发生在Firefox和Chrome中。我在这里错过了什么?
页面刷新意味着什么?你按下'f5按钮'来刷新它。 – 2013-02-18 04:36:54
@Ravi是的,我按f5 – 2013-02-18 04:40:22
'dataType:'json''丢失了,你在成功函数中得到了什么'try.console.log(result)'。 – Jai 2013-02-18 04:41:09