JS让一个DIV变成个聊天窗口

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
    <style type="text/css">
        #Chat
        {
            550px;
            height: 200px;
            padding: 6px;
            overflow-y: scroll;
            word-break: break-all;
            background: #ccc;
        }
    </style>

    <script language="javascript" type="text/javascript">
    function $(c){return document.getElementById(c);}
     function SendMsgss()
     {
       var MSg= $("msg").value;
       var newFontElem = document.createElement("font");
      newFontElem.innerHTML =MSg+"<br/>";
      $("Chat").appendChild(newFontElem);
       $("Chat").scrollTop= $("Chat").scrollHeight;//每次收到消息吧滚动条拉到最下面

//       var MSg= $("msg").value; 这个更简单但是为了后台Ajax返回等。。。。
//       var msgK=$("Chat").innerHTML+=MSg+"<br/>";
     }
    </script>

</head>
<body>
    <form id="form1">
    <div id="Chat">
    </div>
    <input type="text" id="msg" />
    <input type="button" id="send" value="SendMsgss" onclick="SendMsgss()" />

    </form>
</body>
</html>

 查看实例

原文地址:https://www.cnblogs.com/hun_dan/p/1598198.html