我自己试出来了,其实很简单,如下:
    var stuImg = document.createElement("img");
    stuImg.src = "../images/stu_photos/10.jpg";
    var hvsw = stuImg.height/stuImg.width;
    stuImg.style.width=99+"px"
    stuImg.style.height=99*hvsw+"px";
怎么就没人回答呢?是不是都睡了?

解决方案 »

  1.   

    function ScalePhoto(pic, w, h){
    var scale = pic.width/pic.height;
    pic.height = h; pic.width = h * scale;
    if(pic.width > w){ pic.width = w; pic.height = w/scale; }
    }
      

  2.   


    <body></body>
    <script>
    var stuImg = document.createElement("img"); 
    stuImg.src = "http://www.baidu.com/img/baidu_logo.gif"; 
    stuImg.attachEvent("onreadystatechange",function(){
    if(stuImg.readyState=="complete")
    {
    //if (stuImg.width>99)
    //{
    stuImg.height = stuImg.height*99/stuImg.width;
    stuImg.width = 99;
    //}
    }
    });
    document.body.appendChild(stuImg);
    </script>