From 15ce68cd6ea8a5c53e110d324a2156a909982501 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 26 Apr 2026 00:36:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=80=E6=9C=89=20onclick=20=E5=86=85?= =?UTF-8?q?=E8=81=94=E6=94=B9=E4=B8=BA=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 对话列表:新建按钮、对话项、删除按钮使用事件委托 - 对话页面:返回、清空、发送按钮使用 addEventListener - 快捷语句按钮使用事件监听 - 消息操作按钮(复制、重新生成、删除)使用事件监听 - 修复动态生成 HTML 后 onclick 无法正确绑定的作用域问题 --- www/app.js | 95 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/www/app.js b/www/app.js index 42e311c..d674b4e 100644 --- a/www/app.js +++ b/www/app.js @@ -13,16 +13,19 @@ let conversations = []; // 对话列表 let currentConversation = null; // 当前对话 let isLoading = false; -// DOM 元素 -const appContainer = document.getElementById('app'); -const messagesContainer = document.getElementById('messagesContainer'); -const messagesDiv = document.getElementById('messages'); -const userInput = document.getElementById('userInput'); -const sendBtn = document.getElementById('sendBtn'); -const welcome = document.getElementById('welcome'); +// DOM 元素(初始为 null,在 openConversation 时重新获取) +let appContainer = null; +let messagesContainer = null; +let messagesDiv = null; +let userInput = null; +let sendBtn = null; +let welcome = null; // 初始化 document.addEventListener('DOMContentLoaded', () => { + // 初始化 appContainer + appContainer = document.getElementById('app'); + // 从本地存储加载对话列表 const saved = localStorage.getItem('conversations'); if (saved) { @@ -68,19 +71,19 @@ function showConversationList() {