图像的自然宽度返回零...就是这样,为什么?
var newimage = new Image();
newimage.src = 'retouche-hr' + newlinkimage.substring(14,17) + '-a.jpg';
var width = newimage.naturalWidth;
alert (width);
求助,我不知道为什么!
*** 该路径良好,图像显示!
最佳答案
我猜这是因为您没有等待图像加载 - 试试这个:
var newimage = new Image();
newimage.src = 'retouche-hr' + newlinkimage.substring(14,17) + '-a.jpg';
newimage.onload = function()
{
var width = this.naturalWidth;
alert(width);
}
关于javascript - 图像自然宽度返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1645166/