Javascript 如何将复选框中选定值的值与数字进行比较

Javascript 如何将复选框中选定值的值与数字进行比较,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,我必须将复选框中选定值的值与从json获得的数字数据进行比较 var multiQ= new Array(); var questionIndex = 0; var grade=0; function updateQuestion(direction) { questionIndex += direction; if (questionIndex <multiQ.length && questionIndex >= 0) { $("#

我必须将复选框中选定值的值与从json获得的数字数据进行比较

var multiQ= new Array();
var questionIndex = 0;
var grade=0;

function updateQuestion(direction) {
    questionIndex += direction;
    if (questionIndex <multiQ.length && questionIndex >= 0) {
        $("#question").html(multiQ[questionIndex].question);
        $('#answers').empty();
        $.each(multiQ[questionIndex].answers, function(key, val) {
            $('#answers').append('<label><input type="checkbox" value="key" id="checkboxid" onchange="test(this)" >' + val + '</label>');
            console.log(typeof(val));

        });
        console.log(multiQ[questionIndex].correct_a);     
    }
    else {
        questionIndex -= direction;
    }
} 
function test() {
                $('input:checked').each(function () {
                    console.log("grade");
                    if (this.value == multiQ[questionIndex].correct_a) {
                        grade=+1;

                    }
                });
            };
var multiQ=new Array();
var指数=0;
var等级=0;
函数更新(方向){
问题指数+=方向;
如果(问题索引=0){
$(“#问题”).html(multiQ[questionIndex].question);
$(“#答案”).empty();
$.each(multiQ[questionIndex]。答案,函数(键,val){
$(“#答案”)。追加(“”+val+“”);
控制台日志(类型(val));
});
log(multiQ[questionIndex].correct_a);
}
否则{
问题指数-=方向;
}
} 
功能测试(){
$('input:checked')。每个(函数(){
控制台日志(“等级”);
if(this.value==multiQ[questionIndex]。更正a){
职等=+1;
}
});
};

测试函数不起作用。

你在哪里调用
text()
?你没有在代码中的任何地方调用
text()
函数我忘了写这个。。。添加它。它在哪里失败?如果声明?你打印出'this.value'和'multiQ[questionIndex].correct_a'来检查里面有什么吗?@poodle我试着在控制台中打印这个.value。这是一把打印好的钥匙