我有下面的代码(我知道这只是一堆代码中的一个功能,但希望它已经足够了)。控制台为var userAnswer = currentBlank.value;
提供错误“无法读取未定义的属性值”。适用的DOM(我认为DOM将比html源更有用)直接在下面(在图片中)和我遇到问题的javascript函数就在下面。我似乎无法弄清楚出了什么问题。想到也许新的眼睛可能会。
var allBlanksLoc = document.getElementById('text');
allBlanksLoc.style.display = 'block';
var allBlanks = allBlanksLoc.getElementsByTagName('input');
var sortedblanks = blanks.sort(function(a, b){
return a - b
});
var wrongBlanks = 0; // logs how many blanks were answered wrongly over all
var rightBlanks = 0; // logs how many blanks were answered rightly over all
var testAnswersArea = document.getElementById('testAnswers');
finalAnswers = "";
var blankNum = 0;
for (var i = 0; i < wordlist.length; i++) {
if (indicesOfBlanks[i]) {
var currentBlank = allBlanks[blankNum];
var wordNum = sortedblanks[blankNum];
var blankWord = wordlist[wordNum];
var blankWordUp = wordlistUpper[wordNum];
var usrAnswer = currentBlank.value;
if (usrAnswer != blankWord && usrAnswer != blankWordUp) {
finalAnswers += "<del style=\"font: red;\">" + currentBlank.value + "</del> <span style=\"font: green;\">" + blankWordUp + "</span> ";
} else {
finalAnswers += "<span style=\"font: green;\">" + currentBlank.value + "<span>";
}
blankNum++;
}
else {
finalAnswers += wordlistUpper[i] + " ";
}
}
testAnswersArea.innerHTML = finalAnswers;
答案 0 :(得分:2)
wordList
的元素多于allBlanks
因此,allBlanks[blankNum]
为undefined
。