fix: 快捷语句按钮点击无反应
- 改用 data-text 属性存储文本 - 使用事件监听绑定点击事件 - 避免 inline onclick 在动态渲染中的作用域问题
This commit is contained in:
@@ -139,9 +139,9 @@ function openConversation(id) {
|
|||||||
<h2>你好!我是AI助手</h2>
|
<h2>你好!我是AI助手</h2>
|
||||||
<p>有什么可以帮助你的吗?</p>
|
<p>有什么可以帮助你的吗?</p>
|
||||||
<div class="quick-actions">
|
<div class="quick-actions">
|
||||||
<button onclick="sendQuickMessage('介绍一下你自己')">介绍一下你自己</button>
|
<button class="quick-btn" data-text="介绍一下你自己">介绍一下你自己</button>
|
||||||
<button onclick="sendQuickMessage('帮我写一段代码')">帮我写代码</button>
|
<button class="quick-btn" data-text="帮我写一段代码">帮我写代码</button>
|
||||||
<button onclick="sendQuickMessage('解释一个概念')">解释概念</button>
|
<button class="quick-btn" data-text="解释一个概念">解释概念</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="messages" id="messages"></div>
|
<div class="messages" id="messages"></div>
|
||||||
@@ -174,6 +174,15 @@ function openConversation(id) {
|
|||||||
// 渲染消息
|
// 渲染消息
|
||||||
renderMessages();
|
renderMessages();
|
||||||
userInput.focus();
|
userInput.focus();
|
||||||
|
|
||||||
|
// 绑定快捷按钮事件
|
||||||
|
document.querySelectorAll('.quick-btn').forEach(btn => {
|
||||||
|
btn.addEventListener('click', () => {
|
||||||
|
const text = btn.getAttribute('data-text');
|
||||||
|
userInput.value = text;
|
||||||
|
sendMessage();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除对话
|
// 删除对话
|
||||||
|
|||||||
Reference in New Issue
Block a user