拼接功能冻结程序

时间:2018-01-18 03:43:03

标签: javascript arrays

我正在编写一个多项选择测验,其中用户输入他们自己的问题和答案并开发测验。我在创建按钮时遇到问题,按下该按钮会删除存储在数组中的其中一个问题。这是我到目前为止...任何帮助将不胜感激。

bodyText = bodyText + '<input type="button" id="btnDeleteQuestion" 
  value="Delete a question" onClick="questionBank.splice(2,1)">';

我遇到的问题^^^^

 function initialiseQuiz() {
    var bodyText = '<h1>Multichoice quiz</h1><h2>Quiz Setup</h2>';
if(questionBank.length == 0) {
    bodyText = bodyText + '<p>There are no questions defined.  
      Please define at least one question.</p>';
}
else {
    bodyText = bodyText + '<p>Questions currently in the question bank:</p>';
    bodyText = bodyText + '<ul>';
    for(var i=0; i<questionBank.length;i++) {
        bodyText = bodyText + '<li>' + 
            questionBank[i]['questionText'] + '</li>';
    }
    bodyText = bodyText + '</ul>';
    bodyText = bodyText + 
        '<p>Create the quiz, delete or add more questions. </p>';

}

bodyText = bodyText + '<input type="button" id="btnDefineQuestion" 
    value="Define a question" onClick="defineQuestion(' + 
        questionBank.length +', 1);" />';

if(questionBank.length > 0) {
    bodyText = bodyText + '<input type="button" 
        id="btnCreateQuiz" value="Create the quiz"   
        onClick="displayQuestions(
            document.getElementById(\'cmbNumQuestions\').value);" />';
    bodyText = bodyText + '<input type="button" id="btnDeleteQuestion" 
        value="Delete a question" onClick="questionBank.splice(2,1)">';
    bodyText = bodyText + '<p><label for="cmbNumQuestions">
        Choose how many questions to display: </label>';
    bodyText = bodyText + '<select id="cmbNumQuestions">';


        for(var i=0;i<questionBank.length;i++) {
            bodyText = bodyText + '<option value="' + Number(i+1) +'" ';

            if(i==questionBank.length-1) bodyText = bodyText + 
                'selected="selected" ';

            bodyText = bodyText + '>' + Number(i+1)  +'</option>';
        }

    bodyText = bodyText + '</select></p>';
}
    document.body.innerHTML = bodyText;

}

0 个答案:

没有答案