Javascript 数组的动态数组

Javascript 数组的动态数组,javascript,arrays,Javascript,Arrays,我正在创建一个在线测试页面,希望捕获错误的答案并插入另一个数组。我的代码如下。我做错了什么?提前谢谢 var ar, wqs, wqpos = 0; var oneq = new Array(5); function renderQuestion() { test = _("test"); if(pos >= ar.length) { _("test_status").innerHTML = "Test Completed"; pos = 0; co

我正在创建一个在线测试页面,希望捕获错误的答案并插入另一个数组。我的代码如下。我做错了什么?提前谢谢

var ar, wqs, wqpos = 0;
var oneq = new Array(5);
function renderQuestion()
{
    test = _("test");
  if(pos >= ar.length)
  {
    _("test_status").innerHTML = "Test Completed";
    pos = 0;
    correct = 0;
    wqpos = 0;
    return false;
   }
question = ar[pos][1];
..... rest of code
<input type='radio' name='choices' value='A'> "+chA+"<br>;
...... rest of code
<button onClick='checkAnswer()'>Submit Answer</button>;
}   
 function checkAnswer()
{
choices = document.getElementsByName("choices");
for(var i=0; i<choices.length; i++)
{
    if(choices[i].checked)
    {
        choice = choices[i].value;
    }
}
if(choice == ar[pos][5])
{
    correct++;
}
else
{
oneq = [ar[pos][1], ar[pos][2], ar[pos][3], ar[pos][4], ar[pos][5]];

我不明白你的问题,如果我不能解决它。 但是,我读了你们的代码,我认为方法renderQuestion()有问题。因为:

var ar, wqs, wqpos = 0; // ar is undefined
因此,在方法renderQuestion()中检查:

我认为应该为变量设置默认值


谢谢。

Sr.我不明白你的问题,如果我不能解决它的话。 但是,我读了你们的代码,我认为方法renderQuestion()有问题。因为:

var ar, wqs, wqpos = 0; // ar is undefined
因此,在方法renderQuestion()中检查:

我认为应该为变量设置默认值


谢谢。

您遇到了什么错误?请缩进您的代码。问题:当我尝试将oneq数组添加到wqs数组时,什么都没有发生。在我尝试将oneq添加到wqs之前,该程序运行良好。您遇到了什么错误?请缩进您的代码。问题:当我尝试将oneq数组添加到wqs数组时,什么都没有发生。在我尝试将oneq添加到wqs之前,该程序运行良好。
if(pos >= ar.length) // ar.length is error: Uncaught TypeError, because ar is undefined