是所有图片的话var height=100;
var width=100;
var arrImg = document.getElementsByTagName("image");
for(var i=0;i<arrImg.length;i++)
{
arrImg[i].style.width=width;
arrImg[i].style.width=height;
}

解决方案 »

  1.   

    function pub_PhotoFit(obj,options)

    //var defaultOptions = {}
       // Object.extend(options || {}, defaultOptions);
    if(!options) options = {};
    var W =  obj.offsetWidth;
    var H = obj.offsetHeight;
    var tWidth = options.width || 100;
    var tHeight = options.height || 92;
    if(W > tWidth)
    {
    var P = H / W;
    obj.style.width = tWidth;
    obj.style.height = P * tWidth;
    }
    if(H > tHeight)
    {
    var P = W / H;
    obj.style.height = tHeight;
    obj.style.width = P * tHeight;
    }
    }
      

  2.   

    PhotoFit(img,{width:100,height:100})
    img:要缩放的图片
    width:最大宽度,
    height: 最大高度