function imgscale(_img,_width,_height) { var image=new image(); image.src=_img.src; var width=_width;//预先设置的所期望的宽的值 var height=_height;//预先设置的所期望的高的值 if(image.width>=width||image.height>=height){//现有图片只有宽或高超了预设值就进行js控制 w=image.width/width; h=image.height/height; if(w>h){//比值比较大==>宽比高大 //定下宽度为width的宽度 _img.width=width; //以下为计算高度 _img.height=image.height/w; } else {//高比宽大 //定下宽度为height高度 _img.height=height; //以下为计算高度 _img.width=image.width/h; } } } //用于新闻信息显示中图片的自动缩放 function newimgscale(_img) { var _width=660; var _height=600; var image=new image(); image.src=_img.src; var width=_width;//预先设置的所期望的宽的值 var height=_height;//预先设置的所期望的高的值 if(image.width>=width||image.height>=height){//现有图片只有宽或高超了预设值就进行js控制 w=image.width/width; h=image.height/height; if(w>h){//比值比较大==>宽比高大 //定下宽度为width的宽度 _img.width=width; //以下为计算高度 _img.height=image.height/w; } else {//高比宽大 //定下宽度为height高度 _img.height=height; //以下为计算高度 _img.width=image.width/h; } } }