'commit'
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user