//实际图片的宽高 var hei = $("#curtanDiv")[0].height; var wid = $("#curtanDiv")[0].width; //容器的宽高 var czhei = parseInt($("#BankChange").css(‘height‘)) - 35; var czwid = parseInt($("#BankChange").css(‘width‘)); if(wid > czwid){//当宽超出 if(hei > czhei){//宽和高都超出 if(wid > hei){//宽>高,横版 $("#curtanDiv").css({"width":czwid+"px","height":"auto"}) }else{//高>宽,竖版 //竖版图,当修改高度后宽度仍超出 var temPic = $("#curtanDiv").css({"width":"auto","height":czhei+"px"}); var temwid = $("#curtanDiv")[0].width; if(temwid > czwid){ $("#curtanDiv").css({"width":czwid+"px","height":"auto"}) }else{ $("#curtanDiv").css({"width":"auto","height":czhei+"px"}); } } }else{//只有宽超出 $("#curtanDiv").css({"width":czwid+"px","height":"auto"}) } }else{//宽不超出 if(hei > czhei){//只有高超出 $("#curtanDiv").css({"width":"auto","height":czhei+"px"}) }else{//宽和高都没超出 // if(wid > hei){//宽>高,横版 // $("#img2").css({"width":"802px","height":"auto"}) // }else{//高>宽,竖版 // $("#img2").css({"width":"auto","height":"502px"}) // } } }