var im = document.createElement("img");
            im.setAttribute("width", "100px");
            im.setAttribute("height", "100px");
            im.setAttribute("src", "1.jpg");
father.appendChild(im);原图很大,所以我设置了宽高,可是显示出来后,好像宽高没有起作用,图片还和原图一样大。
怎么办好。

解决方案 »

  1.   


    var im = document.createElement("img");
     im.setAttribute("src", "1.jpg");//这个放前面 
                im.setAttribute("width", 100);//这里不要单位,下同
                im.setAttribute("height", "100px");
               
    father.appendChild(im);
      

  2.   


    <div id="father"></div><script type="text/javascript">
    <!--
    window.onload = function()
    {
    var father = document.getElementById('father');
    var im = document.createElement("img");
    father.appendChild(im);
    im.setAttribute("width", "10");
    im.setAttribute("height", "10");
    im.setAttribute("src", "http://www.bgscript.com/images/youxin.jpg");
    }
    //-->
    </script>