0

我知道以前有人问过这个问题,但我似乎无法做到这一点。它总是返回未定义的错误。

var currentAnswers = $('input[name="ans"]:checked').map(function() {
    return this.value;
}).get();

$(document).ready (function () {

//

var answers = 
[["Fee","Fi","Fo"], 
["La","Dee","Da"]],
questions = 
["Fee-ing?",
"La-ing?"],
corAns = ["Fee", "La"];

var counter = 0;

var $facts = $('#main_ .facts_div'),
$question = $facts.find('.question'),
$ul = $facts.find('ul'),
$btn = $('.myBtn');


$btn.on('click', function() {
    if (counter < questions.length) {
        $question.text(questions[counter]);

        var ansstring = $.map(answers[counter], function(value) {
            return '<li><input type="radio" name="ans" value="0"/>'
            + value + '</li>'}).join('');
        $ul.html(ansstring);

        var currentAnswers = $('input[name="ans"]:checked').map(function() {
            return this.val();
        }).get();

        var correct = 0;
        if (currentAnswers[counter]==corAns[counter]) {
            correct++;
        }


    }
    else {
        $facts.text('You are done with the quiz ' + correct);
        $(this).hide();
    }
        counter++;
});

//
});

它很长。我只是不知道我做错了什么。

 <div id="main_">
    <div class="facts_div">
        <span class="question"></span>
        <ul></ul>
    </div>
    <div id = "next_button">
    <form>
        <input id="x" type="button" class="myBtn" value="Press Me">
    </form>
    </div>
</div>
</div>

我觉得答案很愚蠢。就像一个未声明的变量或其他东西,但我只是不知道。我很困惑。

4

0 回答 0