jquery添加div实现消息聊天框

上代码

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
* {margin: 0;padding: 0;
}.border {margin-left: 300px;width: 900px;background-color: white;position: relative;border: 1px solid rgb(221, 221, 221);
}.border .border-next {background-color: #dcad50;position: relative;height: 23px;line-height: 40px;display: flex;padding: 10px 60px 10px 80px;
}.border-next .people {background-color: #dcad50;font-size: 20px;color: black;font-family: 楷体;margin-left: 300px;
}.border .border-second {background-color: white;margin-left: 0px;width: 700px;height: 530px;flex: 1;flex-direction: column;overflow-y: auto;border-right: 1px solid rgb(221, 221, 221);border-bottom: 1px solid rgb(221, 221, 221);
}.border .border-img {background-color: white;margin-left: 0px;width: 700px;height: 30px;border-right: 1px solid rgb(221, 221, 221);border-bottom: 1px solid rgb(221, 221, 221);
}.border-bottom {display: flex;width: 700px;height: 120px;background-color: white;overflow: auto;font-size: 20px;border-style: solid;border-color: #FFFFFF;border-right: 1px solid rgb(221, 221, 221);
}.button {display: flex;margin-left: 530px;
}.button .shut {background-color: white;width: 70px;height: 30px;font-size: 20px;text-align: center;border: 1px solid rgb(221, 221, 221);
}.button .send {background-color: white;margin-left: 15px;width: 70px;height: 30px;font-size: 20px;text-align: center;border: 1px solid rgb(221, 221, 221);background-color: #DBAC50;
}.replyChat {display:flex;width: 150px;background: #12B7F5;border-radius: 5px;/* 圆角 */position: relative;margin-left: 500px;align-content: center;margin-bottom: 30px;
}.sendChat {display:flex;width: 150px;background: #E5E5E5;border-radius: 5px;/* 圆角 */position: relative;margin-left: 50px;align-content: center;margin-bottom: 30px;border-color: white white white #E5E5E5;
}.sendChat span {display: inline-block;margin-left: 10px;line-height: 35px;
}.replyChat span {display: inline-block;margin-left: 10px;line-height: 35px;
}.sendChat .arrows {position: absolute;top: 5px;left: -16px;/* 圆角的位置需要细心调试哦 */width: 0;height: 0;font-size: 0;border: solid 8px;border-color: white #E5E5E5 white white;
}.replyChat .arrow {position: absolute;top: 5px;right: -16px;/* 圆角的位置需要细心调试哦 */width: 0;height: 0;font-size: 0;border: solid 8px;border-color: white white white #12B7F5;
}.chatTouXiang {width: 50px;height: 50px;border-radius: 50%; background-repeat: no-repeat;background-size: cover;background-position: center;background-image: url(img/tou.png);
}
.chatCnt{}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>聊天助手</title>
<script src="js/jquery-1.8.3.min.js"></script>
<script>window.onload=function(){$(".arrow").hide();$(".arrows").hide();}document.onkeydown = function(e) {if (e.keyCode == 13 && e.ctrlKey) {// 这里实现换行document.getElementById("sendContent").value += "\n";} else if (e.keyCode == 13) {// 避免回车键换行e.preventDefault();// 下面写你的发送消息的代码f();}}function f() {var cnt = $("#sendContent").val();if(cnt == '')alert('内容不能为空');   if(cnt != ''){var node = document.createElement('div');node.className = 'sendChat';var span = document.createElement('span');span.innerHTML = cnt;var arrow = document.createElement('div');arrow.className = 'arrows';node.appendChild(span);node.appendChild(arrow);$(".border-second").append($(node));$("#sendContent").val('');$.ajax({data : cnt,type : "post",url : "CharServlet?id=" + cnt,dataType : "json",success : function(msg) {var node = document.createElement('div');node.className = 'replyChat';var span = document.createElement('span');span.innerHTML = msg.text;var arrow = document.createElement('div');arrow.className = 'arrow';node.appendChild(arrow);node.appendChild(span);$(".border-second").append($(node));var boderSecondDiv = $('.border-second');var lastChild = boderSecondDiv[0].lastChild;var lastChildH = lastChild.offsetTop;var h = 0;for (var i = 0, len = lastChild.children.length; i < len; i++) {h += lastChild.children[i].offsetHeight;}boderSecondDiv[0].scrollTop = lastChildH + h;},error : function(msg) {alert("请求失败");}});}}
</script>
</head><div class="frame"><div class="border"><div class="border-next"><div class="people">聊天助手</div></div><div class="border-second"><div class="chatCnt"><div class="chatTouXiang"></div>  <div class="sendChat"><span></span><div class="arrows"></div></div></div><div class="replyChat"><span></span><div class="arrow"></div></div><br></div><div class="border-img"></div><textarea id="sendContent" class="border-bottom"></textarea><div class="button"><button class="shut">关闭</button><button id="selectBtn" class="send" onclick="f()">发送</button></div></div>
</div>
</body>
</html>

这里写图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/509334.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据结构实验之链表一:顺序建立链表

Problem Description 输入N个整数&#xff0c;按照输入的顺序建立单链表存储&#xff0c;并遍历所建立的单链表&#xff0c;输出这些数据。Input 第一行输入整数的个数N&#xff1b; 第二行依次输入每个整数。Output 输出这组整数。Example Input 8 12 56 4 6 55 15 33 62 Exam…

VS调试启动编辑并继续功能

在VS调试的过程中&#xff0c;可能需要进行源代码的修改&#xff0c;一般的做法是先停止当前的调试&#xff0c;然后重新编译再进行调试&#xff0c;哪怕做的一点点小的改动&#xff0c;这样做很浪费时间&#xff0c;尤其是当项目比较大&#xff0c;程序的启动和初始化需要较长…

IRP和IO_STACK_LOCATION

当一个应用程序调用函数去操作某个设备时&#xff0c;比如调用createFile,deviceIOControl,等等时&#xff0c;I/O管理器为此函数创建一个IRP数据结构对象和一个IRP_STACK_LOCATION数据结构对象数组。 &#xff08;数组个数等于驱动程序堆栈上驱动的个数&#xff09;。IRP对象中…

IRQL

转自&#xff1a;http://blog.csdn.net/changsha2011/article/details/6895529 最近开始入门windows 驱动开发&#xff0c;遇到一个IRQL。不知道何解&#xff0c;于是找了些资料&#xff0c;顺带记录下。下面的东西可能有不准确&#xff0c;如发现错误之处请指正&#xff0c;以…

#pragma code_seg(INIT)/code_seg(PAGE)

转自&#xff1a;http://blog.chinaunix.net/uid-24504987-id-161192.html Windows规定有些虚拟内存可以交换到文件中&#xff0c;这类内存被称为分页内存 有些虚拟内存 永远不会交换到文件中&#xff0c;这些内存叫非分页内存 #define PAGEDCODE code_seg(“PAGE”);//分页内…

JSON.stringify() 方法

JSON.stringify() 方法是将一个JavaScript值(对象或者数组)转换为一个 JSON字符串&#xff0c;如果指定了replacer是一个函数&#xff0c;则可以替换值&#xff0c;或者如果指定了replacer是一个数组&#xff0c;可选的仅包括指定的属性。 语法 JSON.stringify(value[, repla…

师--链表的结点插入

Problem Description 给出一个只有头指针的链表和 n 次操作&#xff0c;每次操作为在链表的第 m 个元素后面插入一个新元素x。若m 大于链表的元素总数则将x放在链表的最后。Input 多组输入。每组数据首先输入一个整数n(n∈[1,100])&#xff0c;代表有n次操作。接下来的n行&…

BeanUtils工具的使用(转载)

原文章地址&#xff1a;https://www.cnblogs.com/vmax-tam/p/4159985.html BeanUtils工具 什么是BeanUtils工具 BeanUtils工具是一种方便我们对JavaBean进行操作的工具&#xff0c;是Apache组织下的产品。 BeanUtils工具一般可以方便javaBean的哪些操作&#xff1f; 1&…

线程可警告状态以及APC队列

转自&#xff1a;http://blog.csdn.net/qq_22423659/article/details/53425828 一、线程可警告状态的真实含义 1、通过另一些方法让线程"暂停"(非SuspendThread方法&#xff0c;比如SleepEx&#xff0c;wait函数族等)&#xff0c;并可以进入一种称之为 Alterable的状…

数据结构实验之链表三:链表的逆置

Problem Description 输入多个整数&#xff0c;以-1作为结束标志&#xff0c;顺序建立一个带头结点的单链表&#xff0c;之后对该单链表的数据进行逆置&#xff0c;并输出逆置后的单链表数据。Input 输入多个整数&#xff0c;以-1作为结束标志。Output 输出逆置后的单链表数据。…

DBUtils使用详细示例(转载)

https://www.cnblogs.com/smyhvae/p/4085684.html

APC异步过程调用

转自&#xff1a;http://blog.sina.com.cn/s/blog_c2ef450f010192hx.html APC 异步过程调用 记得第一次看见这个名词的时候&#xff0c;觉得云里雾罩&#xff0c;然而上网看了下它的介绍&#xff0c;感觉说的都是没头没脑的 然而今天&#xff0c;我再次接触了它&#xff0c;我将…

张小龙:如何把产品做简单

今天从一个小故事开始讲&#xff1a;为什么苹果的手机只有一个按钮&#xff1f; &#xff08;台下&#xff1a;我觉得对于用户来说&#xff0c;只有一个按钮不会有太多的干扰&#xff0c;只要从这里开始&#xff0c;其它的菜单都在这里面了&#xff0c;这是我个人的一些想法。&…

数据结构实验之链表九:双向链表

Problem Description 学会了单向链表&#xff0c;我们又多了一种解决问题的能力&#xff0c;单链表利用一个指针就能在内存中找到下一个位置&#xff0c;这是一个不会轻易断裂的链。但单链表有一个弱点——不能回指。比如在链表中有两个节点A,B&#xff0c;他们的关系是B是A的后…

不敢死队问题

Problem Description 说到“敢死队”&#xff0c;大家不要以为我来介绍电影了&#xff0c;因为数据结构里真有这么道程序设计题目&#xff0c;原题如下&#xff1a; 有M个敢死队员要炸掉敌人的一个碉堡&#xff0c;谁都不想去&#xff0c;排长决定用轮回数数的办法来决定哪个战…

槽边往事

http://chuansong.me/account/bitsea?start12

数据结构实验之链表五:单链表的拆分

Problem Description 输入N个整数顺序建立一个单链表&#xff0c;将该单链表拆分成两个子链表&#xff0c;第一个子链表存放了所有的偶数&#xff0c;第二个子链表存放了所有的奇数。两个子链表中数据的相对次序与原链表一致。Input 第一行输入整数N;&#xff1b; 第二行依次输…

聊天机器人调用API实现

后端调用API&#xff1a; package com.mychat.servlet;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder;…