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