在此代码中:
document.getElementById()
document
是具有属性和方法的对象吗?
如果是,getElementById()
是此对象上的方法吗?
如果否,则考虑什么document
和getElementById
?
是的, document
是一个对象。
typeof document; // "object"
和getElementById
是该对象上的属性。
在浏览器中,document
是Document
的实例。 document instanceof Document
=> true
。
它代表整个HTML页面。document
是window
的属性。 window.document === document
=> true
。
因此它可以用作全局对象。