javascript 为什么我收到“ReferenceError: getElementById 未定义”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19507650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:49:56 来源:igfitidea点击:
Why am I getting "ReferenceError: getElementById is not defined"?
提问by novicePrgrmr
I have a little JavaScript code I wrote, and for some reason I'm getting an error saying:
我写了一些 JavaScript 代码,由于某种原因,我收到一条错误消息:
ReferenceError: getElementById is not defined
Here is the function:
这是函数:
window.onload=function()
{
clearAll();
updatePizzaToppings();
updatePizzaToppings();
updatePizzaToppings();
updatePizzaToppings();
};
function updatePizzaToppings()
{
var checkBox=getElementById('selectBacon');
var pic=getElementById('BaconPic');
if (checkBox.checked)
{
pic.style.visibility='visible';
}
else
{
pic.style.visibility='hidden';
}
};
I've made a little JSFiddle for it as well.
我也为它制作了一个小 JSFiddle。
回答by I?ya Bursov
You need to use document.getElementById()