关键语句:
if(div.style.display == "none")
    div.style.display = "";
else
    div.style.display = "none";用display = “none”来隐藏div!

解决方案 »

  1.   

    谢谢大哥,但是怎么移动底下这个DIV到上面啊
      

  2.   


    <style>
    .a {border:1px solid red;width:200;height:100;margin-top:100px;margin-left:100px;}
    </style>
    <div id="div1" class="a">
    <input type="button" value="Click" onclick="hidden()">
    </div>
    <div class="a">
    sfsdfdsfdsfsdfsdf
    </div>
    <script>
    function hidden(obj)
    {
    document.getElementById("div1").style.display="none";
    }
    </script>不用移动下边的
      

  3.   

    如果你的div没有top值的话,就不用管它,直接隐藏上面的div,下面的div会自动上去。如果有top值的话,这就比较讨厌了,要修改下面div的top值。
    所以,可能的话,最好不要设置top值!
    我也是刚学,如有不对的地方,欢迎各位指出!
      

  4.   

    解决了
    //事件函数
    function nextToResult(){
    var div2 = document.getElementById("div2");//下面的div
    document.getElementById("div1").style.visibility="hidden";//上面的div隐藏

    div2.style.position = "absolute";
    div2.style.top = 0;
    div2.style.left = 0; div2.style.visibility="visible";

    }但现在的问题是,div2.style.position = "absolute";这句话是什么意思,我不加这句话,div2就移动不了
      

  5.   

    我这下面的div无法自动上去啊
      

  6.   

    相对定位和绝对定位:relative、absolute
      

  7.   

    改成document.getElementById("div1").style.display="none";//上面的div隐藏使用display,不适用visibility
      

  8.   

    if(div.style.display == "none")
        div.style.display = "";
    else
        div.style.display = "none";
    上面隐藏了,下面的自动就上去了
      

  9.   

    如果是绝对定位的话, 请用z-index. 什么都解决了.