我知道这个主题有很多主题,但这些主题都没有解决我的问题。
我有一个javascript代码,其中有几个函数,大约一个小时后我终于发现在特殊函数下定义的所有函数都不起作用而且错误" ReferenceError:Can&#39 ;找到变量:functionName"将出现,并且在该特殊功能之上定义的所有其他功能都正常工作。 我的问题是,我无法找出造成这个问题的特殊功能有什么问题......任何人都可以帮助我吗?
这是特殊功能:
function shift(btn) {
if (!shiftPressed) {
document.getElementById("keyShift1").style.background = "rgb(180,50,0)";
document.getElementById("keyShift2").style.background = "rgb(180,50,0)";
for (var i = 65; i <= 90; i++) {
var id = "key" + String.fromCharCode(i);
document.getElementById(id).innerHTML = document.getElementById(id).value.toUpperCase();
}
document.getElementById("key~").innerHTML = "`";
shiftPressed = !shiftPressed;
} else {
document.getElementById("keyShift1").style.background = "black";
document.getElementById("keyShift2").style.background = "black";
document.getElementById("key~").innerHTML = "~";
if (!capsPressed) {
for (var i = 65; i <= 90; i++) {
var id = "key" + String.fromCharCode(i);
document.getElementById(id).innerHTML = document.getElementById(id).value.toLowerCase();
}
}
shiftPressed = !shiftPressed;
}
答案 0 :(得分:1)
你在功能结束时遗漏了大括号
应该是
function shift(btn) {
if (!shiftPressed) {
document.getElementById("keyShift1").style.background = "rgb(180,50,0)";
document.getElementById("keyShift2").style.background = "rgb(180,50,0)";
for (var i = 65; i <= 90; i++) {
var id = "key" + String.fromCharCode(i);
document.getElementById(id).innerHTML = document.getElementById(id).value.toUpperCase();
}
document.getElementById("key~").innerHTML = "`";
shiftPressed = !shiftPressed;
} else {
document.getElementById("keyShift1").style.background = "black";
document.getElementById("keyShift2").style.background = "black";
document.getElementById("key~").innerHTML = "~";
if (!capsPressed) {
for (var i = 65; i <= 90; i++) {
var id = "key" + String.fromCharCode(i);
document.getElementById(id).innerHTML = document.getElementById(id).value.toLowerCase();
}
}
shiftPressed = !shiftPressed;
}
}