我正在制作系统,通过选择框系统可以回答问题。它到目前为止工作
function changedValue(vraagId) {
currentId = document.getElementById(vraagId+1).value;
valueId = document.getElementById(vraagId).value;
if (currentId == "") {
document.getElementById(valueId+1).disabled = true;
document.getElementById(valueId+2).disabled = true;
document.getElementById(valueId+3).disabled = true;
document.getElementById(valueId+4).disabled = true;
document.getElementById(vraagId+1).value = valueId;
}
else {
document.getElementById(valueId+1).disabled = true;
document.getElementById(valueId+2).disabled = true;
document.getElementById(valueId+3).disabled = true;
document.getElementById(valueId+4).disabled = true;
document.getElementById(currentId+1).disabled = false;
document.getElementById(currentId+2).disabled = false;
document.getElementById(currentId+3).disabled = false;
document.getElementById(currentId+4).disabled = false;
document.getElementById(vraagId+1).value = valueId;
}
}
function removeValue(vraagId) {
currentId = document.getElementById(vraagId+1).value;
document.getElementById(currentId+1).disabled = false;
document.getElementById(currentId+2).disabled = false;
document.getElementById(currentId+3).disabled = false;
document.getElementById(currentId+4).disabled = false;
document.getElementById(vraagId+1).value = "";
if (vraagId == 'vraag1') {
document.getElementById('antwoord01').selected = true;
}
if (vraagId == 'vraag2') {
document.getElementById('antwoord02').selected = true;
}
if (vraagId == 'vraag3') {
document.getElementById('antwoord03').selected = true;
}
if (vraagId == 'vraag4') {
document.getElementById('antwoord04').selected = true;
}
}
但现在我想添加一个系统,在所有问题都得到解答时启用按钮。我想出了一个使用int的系统。一旦问题得到解答,它就会增加1.一旦问题无法回答,它就会删除1.但是,当我向我的脚本添加int beantwoord = 0;
时,它会给我错误
未捕获的ReferenceError:未定义changedValue
我该如何解决这个问题?
答案 0 :(得分:1)
JavaScript是动态类型的(变量可以包含不同类型的数据),因此以下语句将引发错误:
int someVar = 1;
相反,请使用var
声明您的变量,例如
var someVar = 1;