JavaScript 里 window, document, screen, body 这几个名词的区别
在下面这个 StackOverflow 的线索里进行了讨论:
https://stackoverflow.com/questions/9895202/what-is-the-difference-between-window-screen-and-document-in-javascript
window
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
相当于 浏览器 JavaScript 编程环境里的 root 对象,也可以看成是 document 对象模型的父节点。作为全局对象被访问。
window.screen
window 全局对象的一个属性,包含了物理屏幕的尺寸信息。
window.screen or just screen is a small information object about physical screen dimensions.
window.document
window.document or just document is the main object of the potentially visible (or better yet: rendered) document object model/DOM.
页面被渲染后的可见部分对应的 DOM 对象。
body
是上文描述的 document 对象中一个名为 body 的子节点。
Since window is the global object you can reference any properties of it with just the property name - so you do not have to write down window. - it will be figured out by the runtime.
因为 window 是全局对象,因此访问其属性时,可以省略 window. 的写法。
因此通过下列方式访问 window 里的属性,同样有效:
更多Jerry的原创文章,尽在:“汪子熙”:
JavaScript 里 window, document, screen, body 这几个名词的区别相关推荐
- javascript里的document.all用法收集
javascript里的document.all用法 从IE4开始IE的object model才增加了document.all[],来看看document.all[]的Description: ...
- javascript 中的window, document, screen都有什么区别?
谷歌之后,从stackoverflow上找到的高赞答案: https://stackoverflow.com/questions/9895202/what-is-the-difference-betw ...
- JavaScript window.document的属性、方法和事件小结
javascript中window.document的属性.方法和事件的总结,有需要的朋友可参考一下本文章. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的 ...
- 关于js获取屏幕高度和宽度( window.document.body,window.screen)(PC端和移动端)
在使用JS的时候经常遇到的问题就是我需要获取当前屏幕的宽度和高度.每每到这个时候不知道使用哪个: widow.document.body.offsetWidth; window.screen.avai ...
- JS中window.document对象
小知识点注:外面双引号,里面的双引号改为单引号: 在div里面行高设置和整个外面高度一样,才能用竖直居中,居中是行居中 文本框取出来 ...
- HTML Window.document
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =doc ...
- javascript里的面向对象
2019独角兽企业重金招聘Python工程师标准>>> 前言: javascript 项目中原生态的语法用得比较少了,都是基于jQuery开发,但在移动项目中还是比较麻烦的.想整理个 ...
- document 和 window.document
通常我在写javascript的时候从来没有意识到document和window.document之间是有区别的,实际使用过程中也确实没有遇到问题,但是这埋下了非常大的隐患,当出现问题时,这个bug就 ...
- IE里Window的Method列表
ie里window的method列表 alert(sMsg) //弹出一个确认消息框 attachEvent(sEvent,pFunction) //绑定一个函数到某个事件,事件触发时随机执行其中一个 ...
最新文章
- 总有些物理现象颠覆你的想象
- Android 从清单配置文件元数据中获取值
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(11月9日~11月13日)...
- tomcat 页面图片 管理 服务器 配置
- js javascript UTF-8 GB2312编码转换
- [react] 在React中组件和元素有什么区别?
- Taro+react开发(36)每一个节点要一个view包裹
- vmware挂载san存储_戏说 块存储 文件存储 对象存储
- ANDROID 中设计模式的採用--结构型模式
- MySQL 6.子查询
- HDU 3468 HDOJ 3468 A Simple Problem with Integers ACM 3468 IN HDU
- 【python】多进程小结
- Chrome浏览器无法访问网页(移动硬盘)
- android 字幕跑马灯,led跑马灯字幕
- PostgreSQL RULE
- python实现最小二乘法
- 硬件电路设计原理图设计
- missing external certificate的解决方案
- 微信小程序——tabBar使用
- 推荐100首值得听的英文歌【ZT】