在处理'下一步”按钮事件时,需要更新相应的问题。以下是示例代码:
// 声明当前问题索引 var currentQuestionIndex = 0;
// 获取所有问题元素 var questionElements = document.querySelectorAll('.question');
// '下一步”按钮绑定到处理函数 var nextButton = document.querySelector('#next-button'); nextButton.addEventListener('click', handleNextButton);
function handleNextButton() { // 更新当前问题索引 currentQuestionIndex++;
// 隐藏当前问题 questionElements[currentQuestionIndex - 1].classList.add('hidden');
// 显示下一个问题 questionElements[currentQuestionIndex].classList.remove('hidden'); }
在处理'下一步”按钮事件时,通过更新相应的索引并更改显示/隐藏状态来确保问题得以更新。