//图片大小控制ImgD图片路径,ImgW是宽或高 function DrawImage(ImgD,ImgW){ var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0){ if(image.width/image.height>= 1){ if(image.width>ImgW){ ImgD.width=ImgW; ImgD.height=(image.height*ImgW)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } else{ if(image.height>ImgW){ ImgD.height=ImgW; ImgD.width=(image.width*ImgW)/image.height; }else{ //ImgD.width=(image.width*ImgW)/image.height; ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } } console.log(ImgD); // 里面有图片的信息,拿出来用 }