gpt4 book ai didi

javascript - 谁能看出这段 JavaScript 代码有什么问题吗?

转载 作者:行者123 更新时间:2023-12-02 20:31:04 25 4
gpt4 key购买 nike

我有下面的代码(我知道这只是一堆代码中的一个函数,但希望它足够了)。对于 var userAnswer = currentBlank.value;,控制台给出错误“无法读取未定义的属性‘值’”。适用的 DOM(我认为 DOM 比 html 源代码更有用)就在下面(在图片中),而我遇到问题的 javascript 函数就在它的正下方。我似乎无法弄清楚出了什么问题。我想也许新的眼睛能够做到。

alt text

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;

最佳答案

wordListallBlanks 拥有更多元素。
因此,allBlanks[blankNum]未定义

关于javascript - 谁能看出这段 JavaScript 代码有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4129795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com