修复点击发送按钮会收回聊天框的问题
This commit is contained in:
parent
8cf6a23017
commit
d6e94bb591
@ -55,7 +55,7 @@
|
|||||||
<div class="input-row">
|
<div class="input-row">
|
||||||
<!-- 改用 onclick,顺带阻止冒泡 -->
|
<!-- 改用 onclick,顺带阻止冒泡 -->
|
||||||
<input type="text" id="userInput" placeholder="输入你的消息..." onclick="openChat(event)" />
|
<input type="text" id="userInput" placeholder="输入你的消息..." onclick="openChat(event)" />
|
||||||
<button onclick="sendMessage()">发送</button>
|
<button id="sendbutton" onclick="sendMessage()">发送</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ document.getElementById('userInput').addEventListener('keydown', function(event)
|
|||||||
// 控制聊天框显示和隐藏
|
// 控制聊天框显示和隐藏
|
||||||
const chatBox = document.getElementById('chatContainer');
|
const chatBox = document.getElementById('chatContainer');
|
||||||
const inputBox = document.getElementById('userInput');
|
const inputBox = document.getElementById('userInput');
|
||||||
|
const sendBox = document.getElementById('sendbutton');
|
||||||
|
|
||||||
// 点击输入框时打开聊天框
|
// 点击输入框时打开聊天框
|
||||||
function openChat(e) {
|
function openChat(e) {
|
||||||
@ -49,7 +50,7 @@ function toggleChat(show) {
|
|||||||
|
|
||||||
function outsideClickListener(event) {
|
function outsideClickListener(event) {
|
||||||
// 点击目标既不在聊天框也不在输入框里,就收起
|
// 点击目标既不在聊天框也不在输入框里,就收起
|
||||||
if (!chatBox.contains(event.target) && !inputBox.contains(event.target)) {
|
if (!chatBox.contains(event.target) && !inputBox.contains(event.target) && !sendBox.contains(event.target)) {
|
||||||
toggleChat(false);
|
toggleChat(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user