我不知道发生了什么,因为我从来没有遇到过 JS 问题,但我们开始吧。我不断在 Chrome 中使用以下代码收到 Uncaught ReferenceError:
function showShareButtons() {
var buttons = getElementById("sharebtns");
document.buttons.style.visibility = 'visible';
}
有人能告诉我这是怎么回事吗?谢谢!
最佳答案
您不能简单地为变量单独声明 getElementById
。您需要使用 document.getElementById
:
function showShareButtons() {
var buttons = document.getElementById("sharebtns");
buttons.style.visibility = 'visible';
}
即使您最终在代码中使用了 document,它也不会相同,因为无法将变量声明为任何确定的变量。
关于javascript - GetElementById 在 Chrome 中给出 ReferenceError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22596378/