var image = new Image();//new一个image对象
image.src="images/bg.png";
//image.width;
//image.height;
alert("尺寸:"+image.height+"×"+image.width );为什么这样写不能获取到height与width 

解决方案 »

  1.   

    因为你ALERT的时候图片还没加载完;这样:
    var image = new Image();//new一个image对象
            image.src="images/bg.png";
            image.onload=function(){
              alert("尺寸:"+image.height+"×"+image.width );
            }
            //image.width;
            //image.height;