所以我想讀取通過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