'commit'
This commit is contained in:
@@ -323,3 +323,19 @@
|
|||||||
<script src="physics_quiz.js"></script>
|
<script src="physics_quiz.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
<!-- 确保这些元素存在于HTML中 -->
|
||||||
|
<div id="question-container"></div>
|
||||||
|
<div id="score"></div>
|
||||||
|
<button id="submit-btn">提交答案</button>
|
||||||
|
<select id="difficulty-select">
|
||||||
|
<option value="easy">简单难度</option>
|
||||||
|
<option value="medium">中等难度</option>
|
||||||
|
<option value="hard">困难难度</option>
|
||||||
|
</select>
|
||||||
|
<button id="xueban-btn" class="hidden">学伴答疑</button>
|
||||||
|
<div id="result-container"></div>
|
||||||
|
<audio id="audio-player" controls style="display:none"></audio>
|
||||||
|
<button id="record-btn">开始录音</button>
|
||||||
|
<button id="upload-btn">上传音频</button>
|
||||||
|
<progress id="progress-bar" value="0" max="1"></progress>
|
||||||
|
<span id="recording-time">00:00</span>
|
@@ -110,7 +110,7 @@ let isRecording = false;
|
|||||||
let recordingStartTime;
|
let recordingStartTime;
|
||||||
let recordingTimer;
|
let recordingTimer;
|
||||||
|
|
||||||
// DOM元素
|
// DOM元素 <-- 删除此行及以下全局DOM变量声明
|
||||||
const questionContainer = document.getElementById('question-container');
|
const questionContainer = document.getElementById('question-container');
|
||||||
const scoreElement = document.getElementById('score');
|
const scoreElement = document.getElementById('score');
|
||||||
const submitButton = document.getElementById('submit-btn');
|
const submitButton = document.getElementById('submit-btn');
|
||||||
@@ -123,8 +123,35 @@ const progressBar = document.getElementById('progress-bar');
|
|||||||
const recordingTime = document.getElementById('recording-time');
|
const recordingTime = document.getElementById('recording-time');
|
||||||
const resultContainer = document.getElementById('result-container');
|
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();
|
renderQuestions();
|
||||||
submitButton.addEventListener('click', checkAnswers);
|
submitButton.addEventListener('click', checkAnswers);
|
||||||
difficultySelect.addEventListener('change', changeDifficulty);
|
difficultySelect.addEventListener('change', changeDifficulty);
|
||||||
@@ -135,6 +162,9 @@ function initPage() {
|
|||||||
xuebanBtn.classList.add('hidden');
|
xuebanBtn.classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保DOM加载完成后执行初始化
|
||||||
|
window.addEventListener('DOMContentLoaded', init);
|
||||||
|
|
||||||
// 获取难度名称
|
// 获取难度名称
|
||||||
function getDifficultyName(difficulty) {
|
function getDifficultyName(difficulty) {
|
||||||
const names = { easy: '简单难度', medium: '中等难度', hard: '困难难度' };
|
const names = { easy: '简单难度', medium: '中等难度', hard: '困难难度' };
|
||||||
@@ -291,5 +321,5 @@ function uploadAudio() {
|
|||||||
alert('音频上传成功! (模拟)');
|
alert('音频上传成功! (模拟)');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载完成后初始化
|
// 添加DOM加载完成监听
|
||||||
window.addEventListener('DOMContentLoaded', initPage);
|
document.addEventListener('DOMContentLoaded', init);
|
||||||
|
Reference in New Issue
Block a user