我jQuery代码:jQuery的获取图像的宽度
img[i]='img-src';
$("#popimage1").attr("src",img[i]);
alert($("#popimage1").width()); //doesn't give the width of the current image, but it gives for the previous, and for first null
我的html代码:
<img src="" id="popimage1"/>
等等概念是我我加载不同的图片src为每个使用jQuery,然后我做一些宽度和高度的计算。问题是我得到的图像值与前一个计数器i。我做了一个临时的解决方案,通过把
$("#popimage1").hide();
setTimeout(alert($("#popimage1").width(),2000);
$("#popimage1").show();
但它不总是工作,并导致不必要的超时。 而不是警报有另一个使用img宽度和高度的函数,我只是为了方便而写了alert。任何帮助感谢!
可能重复[获取真实图像的宽度和高度的JavaScript在Safari /铬?](http://stackoverflow.com/questions/318630/get-real-image -width-and-height-with-javascript-in-safari-chrome) – Blazemonger
不是真的,我读过它.. – user666
你有没有尝试过使用那里的答案?它应该为你的目的服务。 – Blazemonger