解决方案 »

  1.   

    jQuery(document).ready(function(){
        $('img').each(function(){ //jquery.each()循环读取所有图片
            var height = $(this).height();
            var width = $(this).width();
            if(width>200){
               $(this).css('height',Math.round(height*200/width)+'px');//如果宽度超过200px,高度等比例缩放
            }
        });
    });
      

  2.   

    如果图片宽高被css修改过,一楼获取到的可能就不一定是图片的真正尺寸了。要获取图片的真实尺寸,可以尝试利用Image类重新加载一遍图片:
    var img = new Image();
    img.onload = function(){
        console.log("width:"+img.width);
        console.log("height:"+img.height);
    };
    img.onerror = function(){
        console.log("图片获取失败!");
    };
    var timer = setInterval(function(){
        if(!!img.width){
            clearInterval(timer);
            console.log("width:"+img.width);
            console.log("height:"+img.height);
        }
    },500);
    img.src="[图片地址]";
      

  3.   

    额.我用PHP搞掂了.不过JQUERY貌似不能选择PHP动态生成的图片呢..哎