<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>聊天对话框</title>
<style type="text/css">
*{font-size: 14px; padding:0; margin:0;}
.main{
    position: relative;
    margin: 20px auto;
    border: 1px solid steelblue;
    width: 430px;
    height: 400px;
}
.msgInput{
    display: block;
    width: 406px;
    height: 60px;
    margin: 10px auto;
    
}
.sendbtn{
    position: absolute;
    width: 100px;
    height: 29px;
    bottom: 5px;
    right: 10px;
}
.content{
    list-style: none;
    width: 410px;
    height: 280px;
    margin: 5px auto;
    border: 1px dotted #D1D3D6;
    overflow-y: scroll;
}
.msgContent{
    width:auto;
    max-width: 250px;
    height: auto;
    word-break: break-all;
    margin: 5px;
    padding: 3px;
    border-radius: 5px;
}
.content .left{
    float: left;
    text-align: left;
    background-color: lightgrey;
    clear: both;
}
.content .right{
    float: right;
    text-align: right;
    background-color: yellowgreen;
    clear: both;
}
</style>
</head>
<body>
    <div id="main" class="main">
        <ul id="content" class="content">
            <li class="msgContent left">hello?</li>
            <li class="msgContent left">hello</li>
            <li class="msgContent right">hi</li>
            <li class="msgContent left">hehe</li>
            <li class="msgContent left">goodbye</li>
            <li class="msgContent right">。。。。</li>
            <li class="msgContent right">sdfasdsadfassdfsdfsdfdsfsdfsdfsdfdfasdffasdfasfdasd fasd fasd fasdfasdfasdf</li>
        </ul>
        <textarea id="msg_input" class="msgInput"></textarea>
        <button id="sendbtn" class="sendbtn">发送</button>
    </div>
</body>
</html>
<script src="../../public.js"></script>
<script>
    /*
     发送时,动态创建li 并设置li的样式msgContent right
     */
    document.onkeyup = function(e){
        var e = e || event;
        if( e.keyCode == 13 && e.ctrlKey ){
            var oli = document.createElement("li");
            oli.innerHTML = $id("msg_input").value;
            $id("content").appendChild( oli );
            oli.className = "msgContent right";
            $id("msg_input").value = "";
            oli.scrollIntoView();
        }
    }
</script>

最新文章

  1. spring boot(二):web综合开发
  2. minHash最小哈希原理
  3. java:警告:[unchecked] 对作为普通类型 java.util.HashMap 的成员的put(K,V) 的调用未经检查
  4. 【转】JavaScript中的原型和继承
  5. Easyui表单之按钮的提交
  6. 萝卜白菜,给有所爱——C#和JAVA都会终将被时代淘汰
  7. Web前端性能优化教程07:精简JS 移除重复脚本
  8. SCRUM:第一天任务实现情况
  9. 分布式数据库hbase详解
  10. iOS数据持久化(三)
  11. 【转】Split strings the right way &ndash; or the next best way
  12. mybatis10 实现类代理对象开发
  13. Asp.Net MVC5 格式化输出时间日期
  14. Clone Graph 解答
  15. IOS 特定于设备的开发:Info.plist属性列表的设置
  16. [学习笔记]jQuery实现一些动画效果的方法
  17. SQLite中使用CTE巧解多级分类的级联查询
  18. 用generator改写ajax
  19. 关于在Python2中使用列表推导式会遇到的问题
  20. 壁虎书3 Classification

热门文章

  1. React 使用 PropTypes 进行类型检查
  2. range— 建立一个包含指定范围单元的数组 (數字、字母)
  3. .net 读取/保存 文件 到 局域网 服务器
  4. MATLAB 绘透视图
  5. ML平台_微博深度学习平台架构和实践
  6. innobackupex per table
  7. 数据仓库专题(2)-Kimball维度建模四步骤
  8. elasticsearch 口水篇(1) 安装、插件
  9. windows迁移linux问题集锦
  10. Java-Runoob-高级教程-实例-时间处理:03. Java 实例 - 获取年份、月份等