您好,我正在尝试做一个 jQuery 测验,但是当他们回答了每个答案时,它只是说:问题 1 是假的 问题 2 是真的
有没有办法让我把它改成: 问题 1 是正确的 问题 2 是错误的
或者这是不可能的?
这是测验:http: //jsfiddle.net/trikedgaming/AJ4mj/
$(function () {
/*jshint laxcomma:true */ (function ($) {
function _range(min, max, rand) {
var arr = (new Array(++max - min))
.join('.').split('.')
.map(function (v, i) {
return min + i;
});
return rand ? arr.map(function (v) {
return [Math.random(), v];
})
.sort().map(function (v) {
return v[1];
}) : arr;
}
$.fn.shuffle = function () {
return this.each(function () {
var $this = $(this),
children = $this.children(),
rand = _range(0, children.length - 1, true).map(function (el) {
return children[el];
});
if (children.length) $(rand).appendTo($this);
});
};
}(jQuery));
$('ul').shuffle();
var jQuiz = {
answers: {
q1: 'd',
q2: 'c',
q3: 'a',
q4: 'd',
q5: 'a'
},
questionLenght: 5,
checkAnswers: function () {
var arr = this.answers;
var ans = this.userAnswers;
var resultArr = []
for (var p in ans) {
var x = parseInt(p) + 1;
var key = 'q' + x;
var flag = false;
if (ans[p] == 'q' + x + '-' + arr[key]) {
flag = true;
} else {
flag = false;
}
resultArr.push(flag);
}
return resultArr;
},
init: function () {
$('.btnNext').click(function () {
if ($('input[type=radio]:checked:visible').length == 0) {
return false;
}
$(this).parents('.questionContainer').fadeOut(500, function () {
$(this).next().fadeIn(500);
});
var el = $('#progress');
el.width(el.width() + 120 + 'px');
});
$('.btnPrev').click(function () {
$(this).parents('.questionContainer').fadeOut(500, function () {
$(this).prev().fadeIn(500)
});
var el = $('#progress');
el.width(el.width() - 120 + 'px');
})
$('.btnShowResult').click(function () {
var arr = $('input[type=radio]:checked');
var ans = jQuiz.userAnswers = [];
for (var i = 0, ii = arr.length; i < ii; i++) {
ans.push(arr[i].getAttribute('id'))
}
})
$('.btnShowResult').click(function () {
$('#progress').width(300);
$('#progressKeeper').hide();
var results = jQuiz.checkAnswers();
var resultSet = '';
var trueCount = 0;
for (var i = 0, ii = results.length; i < ii; i++) {
if (results[i] == true) trueCount++;
resultSet += '<div> Question ' + (i + 1) + ' is ' + results[i] + '</div>'
}
resultSet += '<div class="totalScore">True= Correct Answer<br />False= Wrong Answer<br /><br />Your total score is ' + trueCount * 1 + ' / 10</div>'
$('#resultKeeper').html(resultSet).show();
})
}
};
jQuiz.init();
})