我必须将复选框中所选值的值与我从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;
}
});
};
测试功能不起作用。