为什么我收到“ReferenceError: getElementById 未定义”

Why am I getting "ReferenceError: getElementById is not defined"?

本文关键字:getElementById 未定义 ReferenceError 为什么      更新时间:2023-09-26

我写了一点JavaScript代码,由于某种原因,我收到一个错误说:

ReferenceError: getElementById is not defined

这是函数:

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';
    }           
}; 

我也为它做了一个小JSFiddle。

http://jsfiddle.net/CkjkB/5/

你需要

使用document.getElementById()