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.οnlοad=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("请求失败");










