Javascript中的窗口,屏幕和文档有什么区别? [英] What is the difference between window, screen, and document in Javascript?
问题描述
我认为这些术语可以互换使用,作为DOM的全局环境。有什么区别(如果有的话)我应该在何时使用每一个?
I see these terms used interchangeably as the global environment for the DOM. What is the difference (if there is one) and when should I use each one?
推荐答案
窗口
是主要的JavaScript对象根,也就是浏览器中的全局对象,也可以视为文档对象模型的根。您可以在大多数情况下(在浏览器中)以窗口
的形式访问它;
Window
is the main JavaScript object root, aka the global object in a browser, also can be treated as the root of the document object model. You can access it as window
in most of the cases (in the browser);
window.screen
是一个关于物理屏幕尺寸的小信息对象。
window.screen
is a small information object about physical screen dimensions.
window.document
或只是 document
是可见(或更好的:渲染)文档对象模型/ DOM的主要对象。
window.document
or just document
is the main object of the visible (or better yet: rendered) document object model/DOM.
这篇关于Javascript中的窗口,屏幕和文档有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!