RT~ 聊天室是用java+ajax写的,用户发的消息要从下往上走 比如,当前用户端显示的第一条消息是从显示窗口下面显示出来的,第二条消息也是从下面显示的...以此类推 请达人解答具体做法,本人新手!!

解决方案 »

  1.   

    就用appendChild() 按顺序加入,就是你要的效果了。 LZ 
      

  2.   

    简单模拟了一下,应该是这样吧...
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    #chatContainer{
    width:500px; height:100px; overflow:hidden; border:1px solid #ccc; position:relative;
    }
    #chatMsg{
    position:absolute; bottom:0px; overflow:auto; width:100%;
    }
    </style>
    <script type="text/javascript">function sendMsg(){
    var txt = document.getElementById("txtMsg");
    var chat = document.getElementById("chatMsg");

    chat.innerHTML += txt.value +"<br/>";
    chat.scrollTop += 50;

    if(chat.offsetHeight > chat.parentNode.offsetHeight){
    chat.style.height = chat.parentNode.offsetHeight + "px";
    }

    txt.value = "";
    txt.focus();
    }
    </script>
    </head><body>
    <div id="chatContainer">
    <div id="chatMsg"></div>
    </div>
    <input type="text" id="txtMsg" /><input type="button" value=" 发送 " onclick="sendMsg();" />
    </body>
    </html>