前提是图片路径是正确的...
var img = new Image(); img.src="http://www.baidu.com/img/baidu_sylogo1.gif"; img.onload = function(){ alert(this.width); alert(this.height); this.οnlοad=null; }
通过$("#img").attr("width");这种方式获取的值,在图片没有加载完成的时候,是不正确的
前提是图片路径是正确的...
var img = new Image(); img.src="http://www.baidu.com/img/baidu_sylogo1.gif"; img.onload = function(){ alert(this.width); alert(this.height); this.οnlοad=null; }
通过$("#img").attr("width");这种方式获取的值,在图片没有加载完成的时候,是不正确的
转载于:https://www.cnblogs.com/zhouyalei/archive/2012/04/20/2459616.html