什麼是最好的方法來刪除下面的當前問題值,並添加下一個問題,點擊按鈕時。做了一個糟糕的嘗試,並可以做一些幫助。繼承人jsfiddle.測驗 - 添加和刪除節點
var allQuestions = [
{
question: "Who is Prime Minister of the United Kingdom?",
choices: ["David Cameron", "Gordon Brown", "Winston Churchill", "Tony Blair"],
correctAnswer:0
},{
question: "What is 4 + 4?",
choices: ["24", "8", "18", "16"],
correctAnswer:0
},{
question: "What is 5 + 4?",
choices: ["24", "9", "10", "16"],
correctAnswer:0
}];
var button = document.getElementById('next');
var question = document.getElementById("question");
button.onclick = function(){
for(var i=0; i<allQuestions.length;i++){
question.innerHTML = allQuestions[i].question;
}
}
剛注意到第一個答案和這個差不多,這個答案循環回到最後一個問題之後的第一個問題。 – mikeLspohn 2014-10-01 00:39:40
也可能不應該使用我作爲變量,除非您想將整個答案封裝在一個iife中以將其全部封裝到該範圍中。 – mikeLspohn 2014-10-01 00:44:36