我有一个相当恼人的问题。我正在举行一场比赛,比分保持不变。有5个问题。它包含一个带单选按钮的表单。 jQuery检查选择了哪个单选按钮,并在每次给出正确答案时对变量进行计数。编写了以下jQuery代码:
var i = 0;
var correctQuestions = 0;
function readValue(){
var antwoordVraag1 = $('input[name=q1]:checked', '#comp').val();
var antwoordVraag2 = $('input[name=q2]:checked', '#comp').val();
var antwoordVraag3 = $('input[name=q3]:checked', '#comp').val();
var antwoordVraag4 = $('input[name=q4]:checked', '#comp').val();
var antwoordVraag5 = $('input[name=q5]:checked', '#comp').val();
if (i === 0){
$('.question-wrapper-1').fadeOut("slow", function(){
$('.question-wrapper-2').fadeIn("slow");
});
i++;
$('.progress-radio-btn-1').attr('src','common/img/question-btn.png');
$('.progress-radio-btn-2').attr('src','common/img/question-btn-active.png');
if(antwoordVraag1 == 1){
correctQuestions++;
}
console.log('Vragen goed = '+correctQuestions);
}
else if (i === 1){
$('.question-wrapper-2').fadeOut("slow", function(){
$('.question-wrapper-3').fadeIn("slow");
});
i++;
$('.progress-radio-btn-2').attr('src','common/img/question-btn.png');
$('.progress-radio-btn-3').attr('src','common/img/question-btn-active.png');
if(antwoordVraag2 == 1){
correctQuestions++;
}
console.log('Vragen goed = '+correctQuestions);
}
else if (i === 2){
$('.question-wrapper-3').fadeOut("slow", function(){
$('.question-wrapper-4').fadeIn("slow");
});
i++;
$('.progress-radio-btn-3').attr('src','common/img/question-btn.png');
$('.progress-radio-btn-4').attr('src','common/img/question-btn-active.png');
if(antwoordVraag3 == 2){
correctQuestions++;
}
console.log('Vragen goed = '+correctQuestions);
}
else if (i === 3){
$('.question-wrapper-4').fadeOut("slow", function(){
$('.question-wrapper-5').fadeIn("slow");
});
i++;
$('.progress-radio-btn-4').attr('src','common/img/question-btn.png');
$('.progress-radio-btn-5').attr('src','common/img/question-btn-active.png');
if(antwoordVraag4 == 3){
correctQuestions++;
}
console.log('Vragen goed = '+correctQuestions);
}
else if (i === 4){
$('#question-btn').fadeOut(),500;
$('.progress-radio').fadeOut(),500;
$('.question-wrapper-5').fadeOut("slow", function(){
$('.final-wrapper').fadeIn("slow");
});
if(antwoordVraag5 == 3){
correctQuestions++;
}
console.log('Vragen goed = '+correctQuestions);
}
else{
alert('Something went wrong...');
alert(i);
}
}
这在桌面上运行得很好。但是,当我在iPad上测试它时,警报框会给出一个" i"价值86.我不知道如何解决这个问题。
谢谢!