<script type="text/JavaScript"> function setImgSize(img,width,height){ var MaxWidth=width;//设置图片宽度界限 var MaxHeight=height;//设置图片高度界限 var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比 var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比 if(img.offsetWidth>MaxWidth){ img.width=MaxWidth; img.height=MaxWidth*HeightWidth; } if(img.offsetHeight>MaxHeight){ img.height=MaxHeight; img.width=MaxHeight*WidthHeight; } } </script>