jQuery中窗口和文档的区别 [英] difference between window and document in jQuery

查看:78
本文介绍了jQuery中窗口和文档的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道文档和&& window 在jQuery中



这两个常用,但我从来没有得到它们之间的区别。

解决方案

。 。这实际上可能是你意识到的一个更大的问题。 :)



非常简短的答案是。 。 。
$ b

窗口对象代表文档对象被显示出来。事实上,当你在你的代码中引用 document 时,你确实引用了 window.document window 的所有属性和方法都是全局的,因此可以在开始时没有真正指定 window ...例如文档 = window.document alert() = window.alert())。


$ b

c $ c> object是当前加载的DOM文档。 。 。所以,如果你去 http://www.stackoverflow.com 文档对象将被加载构成StackOverflow主页的所有HTML,JS,CSS等。如果您点击此问题的链接,那么文档现在都是构成此问题页面的相同类型的资产。但是,当您更改文档时,您仍然位于窗口中(尽管<$ c的一些属性

对于两个对象(包括标准属性和方法)的大量信息,请查看这些链接:





最后一个注意:虽然不完全准确,但如果您是视觉人物,您可以考虑窗口作为您打开浏览器窗口或选项卡查看网页。 。 。您可能会在浏览时浏览很多文档,但是,如果您从未更改为其他选项卡,则始终位于窗口


i wanna know whats the difference between document && window in jQuery ??

These two are used quite often, but i hv never got the difference between them.

解决方案

Whew . . . that's actually probably a bigger question that you realize. :)

The Extremely Short Answer is . . .

The window object represents the container that the document object is displayed in. In fact, when you reference document in your code, you are really referencing window.document (all properties and methods of window are global and, as such, can be referenced without actually specifying window at the beginning . . . e.g., document = window.document and alert() = window.alert()).

The document object is the currently loaded DOM document . . . so, if you go to http://www.stackoverflow.com, the document object would be all of the HTML, JS, CSS, etc. that are loaded to make up the StackOverflow home page. If you click on the link to this question, the document is now all of the same kinds of assets that make up the page for this question. When you change documents though, you are still in the same window (though some of the properties of the window have changed).

For LOTS of information on the two objects (including standard properties and methods), check out these links:

One last note: While not completely accurate, if you are a visual person, you can think of the window as the browser window or tab that you have open to view web pages . . . you may move through many documents as you are surfing, but, if you never change to a different tab, you are always in the same window.

这篇关于jQuery中窗口和文档的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆