gpt4 book ai didi

javascript - 聊天 发送消息 左接收 右

转载 作者:行者123 更新时间:2023-11-28 05:29:55 24 4
gpt4 key购买 nike

您好,我使用 Javascript 进行了聊天,现在我希望发送的消息显示在左侧,接收的消息显示在右侧。HTML

<div id="chatHtml" style="display: none;">
<link rel="stylesheet" href="style/main.css">
<div id=chatOutput class="chat-output"></div>
<textarea class="form-control" rows="1" id="input-text-chat" placeholder="Enter Text Chat"></textarea>
<div id="chat-container">
</div>
</div>

Javascript

 openChat: function(){
win =window.open('','myconsole',
'width=450,height=500'
+',menubar=0'
+',toolbar=1'
+',status=0'
+',scrollbars=1'
+',resizable=1')
win.document.writeln("<body style='background-color:#ecf0f1'></body>");
chat = document.getElementById("chatHtml").innerHTML;
win.document.write(chat);
win.document.title = "Live Chat";

win.document.getElementById('input-text-chat').onkeyup = function(e) {
if (e.keyCode != 13) return;
// removing trailing/leading whitespace
this.value = this.value.replace(/^\s+|\s+$/g, '');

var a = new Date();
var b = a.getHours(); var c = a.getMinutes(); var d = a.getSeconds();
if(b < 10){b = '0'+b;}
if(c < 10){c = '0'+c;}
if(d < 10){d = '0'+d;}
var time = b+':'+c+':'+d;

if (!this.value.length) return
win.document.getElementById("chat-container").className="chat-Output";
connection.send('<div class="bubbleGET"> <font color="white"> User(' + time + '): ' +this.value+ '</font></div>');
console.log(connection.send);
console.log('User (' + time + '): ' +this.value);
win.document.getElementById("chat-container").className="chat-OutputGET";
appendDIV('<div class="bubble"> <font color="white"> User (' + time + '): ' +this.value+ '</font></div>');
this.value = '';
};
var chatContainer = win.document.querySelector('.chat-output');
function appendDIV(event) {
var div = document.createElement('div');
div.innerHTML = event.data || event;
chatContainer.appendChild(div);
div.tabIndex = 0;
div.focus();
win.document.getElementById('input-text-chat').focus();
}
connection.onmessage = appendDIV;

}
}

win.document.getElementById("chat-c​​ontainer").className="chat-OutputGET";不起作用

这是该类的 CSS:

.chat-Output{
position: absolute; bottom: 2.1em;
margin-left: 0.4em;
padding-left: 0.4em;
overflow: scroll;
word-break: break-word;
}

.chat-OutputGET{
position: absolute; bottom: 2.1em;
margin-right: 0.4em;
overflow: scroll;
word-break: break-word;
}

谢谢:)我不得不说我是网络开发新手。

最佳答案

只需使用float:left

样式中的

clear:both

关于javascript - 聊天 发送消息 左接收 右,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39787166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com