小编fed*_*rce的帖子

未捕获的TypeError:undefined不是函数,在for循环中创建的对象

我正在构建一个小的测验应用程序,用户可以在其中构建自己的测验,但在for循环中创建对象时遇到了问题.

这是Question对象的构造函数:

var question = function(questionNumber, question, choices, correctAnswer) {
    this.questionNumber = questionNumber;
    this.question = question;
    this.choices = choices;
    this.correctAnswer = correctAnswer; //The number stored here must be the location of the answer in the array

    this.populateQuestions = function populateQuestions() {
        var h2 = $('<h2>').append(this.question);
        $('#quizSpace').append(h2);
        for (var i = 0; i < choices.length; i++) {
            //Create the input element
            var radio = $('<input type="radio">').attr({value: choices[i], name: 'answer'});

            //Insert the radio into the DOM
            $('#quizSpace').append(radio);
            radio.after('<br>');
            radio.after(choices[i]);
        }
    };
    allQuestions.push(this); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery object

4
推荐指数
1
解决办法
3148
查看次数

标签 统计

javascript ×1

jquery ×1

object ×1