From 64aee549825db884443d9b4525cab80fc0c8b918 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Thu, 28 Aug 2025 08:42:19 +0800 Subject: [PATCH] 'commit' --- dsLightRag/static/YunXiao/physics_quiz.html | 18 +++++++++- dsLightRag/static/YunXiao/physics_quiz.js | 40 ++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/dsLightRag/static/YunXiao/physics_quiz.html b/dsLightRag/static/YunXiao/physics_quiz.html index e8ef2a65..823e2b4b 100644 --- a/dsLightRag/static/YunXiao/physics_quiz.html +++ b/dsLightRag/static/YunXiao/physics_quiz.html @@ -322,4 +322,20 @@ - \ No newline at end of file + + +
+
+ + + +
+ + + + +00:00 \ No newline at end of file diff --git a/dsLightRag/static/YunXiao/physics_quiz.js b/dsLightRag/static/YunXiao/physics_quiz.js index d3955147..38dc6715 100644 --- a/dsLightRag/static/YunXiao/physics_quiz.js +++ b/dsLightRag/static/YunXiao/physics_quiz.js @@ -110,7 +110,7 @@ let isRecording = false; let recordingStartTime; let recordingTimer; -// DOM元素 +// DOM元素 <-- 删除此行及以下全局DOM变量声明 const questionContainer = document.getElementById('question-container'); const scoreElement = document.getElementById('score'); const submitButton = document.getElementById('submit-btn'); @@ -123,8 +123,35 @@ const progressBar = document.getElementById('progress-bar'); const recordingTime = document.getElementById('recording-time'); const resultContainer = document.getElementById('result-container'); -// 初始化页面 -function initPage() { +// 页面加载完成后初始化 +function init() { + // 添加DOM元素获取逻辑 + const questionContainer = document.getElementById('question-container'); + const scoreElement = document.getElementById('score'); + const submitButton = document.getElementById('submit-btn'); + const difficultySelect = document.getElementById('difficulty-select'); + const xuebanBtn = document.getElementById('xueban-btn'); + const recordButton = document.getElementById('record-btn'); + const audioPlayer = document.getElementById('audio-player'); + const uploadButton = document.getElementById('upload-btn'); + const progressBar = document.getElementById('progress-bar'); + const recordingTime = document.getElementById('recording-time'); + const resultContainer = document.getElementById('result-container'); + + // 检查关键DOM元素是否存在 + const requiredElements = [ + 'question-container', 'score', 'submit-btn', + 'difficulty-select', 'xueban-btn', 'result-container' + ]; + + const missingElements = requiredElements.filter(id => !document.getElementById(id)); + if (missingElements.length > 0) { + console.error('缺少必要的DOM元素:', missingElements); + alert('页面加载失败,请检查HTML结构'); + return; + } + + // 正常初始化 renderQuestions(); submitButton.addEventListener('click', checkAnswers); difficultySelect.addEventListener('change', changeDifficulty); @@ -135,6 +162,9 @@ function initPage() { xuebanBtn.classList.add('hidden'); } +// 确保DOM加载完成后执行初始化 +window.addEventListener('DOMContentLoaded', init); + // 获取难度名称 function getDifficultyName(difficulty) { const names = { easy: '简单难度', medium: '中等难度', hard: '困难难度' }; @@ -291,5 +321,5 @@ function uploadAudio() { alert('音频上传成功! (模拟)'); } -// 页面加载完成后初始化 -window.addEventListener('DOMContentLoaded', initPage); +// 添加DOM加载完成监听 +document.addEventListener('DOMContentLoaded', init);