爲什麼document.body.getElementById(idOfElem)
和document.body.getElementsByName(nameOfElem)
無法正常工作?爲什麼getElementById在文檔以外的元素上不起作用?
和
爲什麼document.body.getElementByTagName(tagOfElem)
和document.body.getElementByClassName(classOfElem)
工作?
在使用第一個,瀏覽器引發此錯誤:
TypeError: document.body.getElementById is not a function[Learn More]
放下'body'部分。它只是'document.getElementById' – j08691
使用'document.getElementById()',如果'idOFelem'不是變量use'「idOFelem」' –
@Teemu OP不問這些方法是幹什麼的。相反,OP對'getElementById'在'body'對象上不可用的困惑,但另一些是。 – evolutionxbox