因为lz的HTML中
第一个div不仅包含了一个img元素,还有一个文本元素(就是那个换行)
lz把html写成下面这样就好了
<div class="oo"><img src="http://zi.csdn.net/button(300x60)_3.jpg"></div>另外,文本元素,也可以通过判断element.nodeType == 3 来判断,并删除

解决方案 »

  1.   

    我测试的没有啊!估计你所谓的底部的空出一行是因为<br><br><br>的原因
    不信你试试下边的代码
    <html>
    <head>
    <style type="text/css">
    <!--.oo{
    border:1px solid #000000;
    width:328px;
    height:240px;
    }
    -->
    </style>
    <script>
    window.onload= function ss(){
    var bian= document.getElementById("hh")
    var xx=document.createElement("img")
    xx.setAttribute("src","http://mat1.qq.com/ent/upday2008/06182.jpg")
    bian.appendChild(xx)
    }</script>
    </head>
    <body >
    头部
    <div class="oo">
    <img src="http://mat1.qq.com/ent/upday2008/06182.jpg">
    </div>底部
    <br><br><br>
    头部
    <div id="hh" class="oo">
    </div>底部
    </body>
      

  2.   

    <div class="oo">
    <img src="http://mat1.qq.com/ent/upday2008/06182.jpg">这里有个换行
    </div>
    创建元素却没有创建换行