JavaScript DOM API 在哪里记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3768606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the JavaScript DOM API documented?
提问by Marc O'Morain
I am a C/C++ programmer, and I am currently playing with some Javascript code, and I am having problems finding where the documentation is for the standard Javascript libraries that are available in the browser.
我是一名 C/C++ 程序员,我目前正在使用一些 Javascript 代码,但我在查找浏览器中可用的标准 Javascript 库的文档位置时遇到了问题。
Specifically, I am setting an onloadcallback function on a HTMLImageElement, created with new Image(). I also want to read about the srcproperty, since it has non-standard behavior - when this property is assigned to, the image is reloaded.
具体来说,我在 上设置了一个onload回调函数HTMLImageElement,用new Image(). 我还想阅读有关该src属性的信息,因为它具有非标准行为 - 当分配给该属性时,将重新加载图像。
Mozilla has some skeleton documentation of the various attributes here: https://developer.mozilla.org/en/DOM/ImageThere is no documentation here, only a list of properties. The onloadproperty is not mentioned. The srcproperty is listed but there is no documentation on it.
Mozilla 在此处提供了各种属性的框架文档:https: //developer.mozilla.org/en/DOM/Image这里没有文档,只有属性列表。该onload未提及财产。该src物业已列出,但没有关于它的文件。
MSDN has has better documentation: http://msdn.microsoft.com/en-us/library/cc197055(VS.85).aspx.
MSDN 有更好的文档:http: //msdn.microsoft.com/en-us/library/cc197055(VS.85).aspx。
My question is 'where are the standard docs'? Is Image()a global variable, or is it a property of windowthe global object? Who writes the API for windowand document? Is there a standard, or does each browser just copy each other?
我的问题是“标准文档在哪里”?是Image()全局变量,还是window全局对象的属性?谁写的APIwindow和document?是否有标准,还是每个浏览器只是相互复制?
回答by bobince
The DOM is actually a separate thing to JavaScript. The DOM can be accessed from other languages, such as VBScript in IE. And general-purpose programming languages like Java, Python, PHP etc have their own non-browser-based DOM libraries.
DOM 实际上是与 JavaScript 不同的东西。DOM 可以从其他语言访问,例如 IE 中的 VBScript。Java、Python、PHP 等通用编程语言都有自己的非基于浏览器的 DOM 库。
The basic DOM operations that work on both HTML and general XML documents can be found in DOM Core; HTML documents get extra methods defined in DOM HTML. These are the latest ‘levels' of support defined by W3; not all browsers support everything in DOM Level 3 Core. But DOM Level 1 Coreis pretty much solid.
可以在DOM Core 中找到适用于 HTML 和一般 XML 文档的基本 DOM 操作;HTML 文档获得在DOM HTML 中定义的额外方法。这些是 W3 定义的最新“级别”支持;并非所有浏览器都支持 DOM Level 3 Core 中的所有内容。但是DOM Level 1 Core非常可靠。
Confusingly, DOM HTML has further developed, but not in its own DOM specification. Instead it is part of HTML5. This standardises a lot of extensions that were already widely supported in browsers, like innerHTML, and adds a bunch more stuff that isn't widely implemented yet (and may be changed before the document is standardised).
令人困惑的是,DOM HTML 得到了进一步的发展,但不是在它自己的 DOM 规范中。相反,它是 HTML5 的一部分。这对浏览器中已经广泛支持的许多扩展进行了标准化,例如innerHTML,并添加了更多尚未广泛实现的内容(并且可能在文档标准化之前进行更改)。
The DOM is only the document object model: it specifies what you get inside the documentobject. It doesn't specify other browser features, like the contents of window. The browser object model (BOM) was previously unstandardised; HTML5 is making the first effort to properly document it.
DOM 只是文档对象模型:它指定了您在document对象内部获得的内容。它没有指定其他浏览器功能,例如window. 浏览器对象模型 (BOM) 以前未标准化;HTML5 正在首先努力正确地记录它。
HTML5 also specifies parts of the browser object model (BOM) that were not previously standardised. Stuff like windowthat isn't directly connected to the documentcontent.
HTML5 还指定了以前未标准化的浏览器对象模型 (BOM) 部分。像window这样的东西与document内容没有直接联系。
The upshot of all this is that there isn't a single document you can go to that will tell you everything about what methods and properties you have available to you in web scripting. Some day DOM Core plus HTML5 will cover it all, but today HTML5 includes a lot you can't rely on, and isn't exactly the most readable of guides even by the standards of standards documents. So yes, I'm afraid you're going to have to continue to check MDC and MSDN for popular support.
所有这一切的结果是,没有一个您可以访问的文档会告诉您有关在 Web 脚本中可用的方法和属性的所有信息。总有一天 DOM Core 加上 HTML5 将涵盖所有内容,但是今天 HTML5 包含了很多您无法依赖的内容,即使按照标准文档的标准,它也不是最易读的指南。所以是的,恐怕您将不得不继续查看 MDC 和 MSDN 以获得流行支持。
Is 'Image' a global variable, or is it a property of 'window' the global object?
“图像”是全局变量,还是全局对象“窗口”的属性?
Imageis specified by HTML5 to be a member of the windowobject, which, being the global context, allows you to refer to it as just Image... that's not quitethe same thing as being a global variable, but it's close enough for most.
Image由 HTML5 指定为window对象的成员,作为全局上下文,允许您将其引用为Image……这与作为全局变量不太一样,但对大多数人来说已经足够接近了。
It is a constructor-function that returns a DOM object implementing the HTMLImageElementinterface (from DOM Level 1 HTML, extended in HTML5). It was originally introduced in Netscape 3.0 as a mechanism for pre-loading images; plus already-created images could be accessed from document.imagesto change their src. Today new Image()doesn't do anything different to document.createElement('img').
它是一个构造函数,返回一个实现HTMLImageElement接口的 DOM 对象(来自 DOM Level 1 HTML,在 HTML5 中扩展)。它最初是在 Netscape 3.0 中作为预加载图像的机制引入的;另外可以访问已经创建的图像document.images以更改它们的src. 今天new Image()没有做任何不同的事情document.createElement('img')。
I also want to read about the 'src' property, since it has non-standard behavior - when this property is assigned to, the image is reloaded.
我还想了解 'src' 属性,因为它具有非标准行为 - 当分配此属性时,图像会重新加载。
Well the image won't be reloaded necessarily, but it may cause the loadevent to be fired on some browsers. Unfortunately this isn't standardised (even in HTML5 as far as I can see). IE, Firefox and Opera fire loadon every srcset (even if the srcis not changed) whereas WebKit (Chrome/Safari) only ever fires it on the initial image load.
好吧,图像不一定会重新加载,但它可能会导致load在某些浏览器上触发该事件。不幸的是,这不是标准化的(就我所见,即使在 HTML5 中)。IE、Firefox 和 Opera 会load在每个src集合上触发(即使src没有更改),而 WebKit(Chrome/Safari)只会在初始图像加载时触发它。
This sort of thing is why there are sites with big tables of differing browser behaviours, and why we still have to actively test on different browsers.
这类事情就是为什么有些网站有不同浏览器行为的大表,以及为什么我们仍然必须在不同的浏览器上积极测试。
回答by papercowboy
New fave: http://devdocs.io/dom/(Devdocs.io in general is pretty awesome for lots of reference material)
新宠:http://devdocs.io/dom/(一般来说,Devdocs.io 对于大量参考资料来说非常棒)
(older) I really like this DOM reference: http://krook.org/jsdom/
(旧)我真的很喜欢这个 DOM 参考:http: //krook.org/jsdom/
回答by user1063287
For newbies, this will really help with understanding what you are working with and separating the concepts of:
对于新手来说,这将真正有助于理解您正在使用的内容并区分以下概念:
Javascript (a language used to access the DOM, other scripting languages can be used),
an HTML or XML document (the markup that forms the basis of a web page)
and the DOM (a model of the document that serves as an API allowing you to manipulate the structure and contents of the document).
Javascript(一种用于访问 DOM 的语言,可以使用其他脚本语言),
HTML 或 XML 文档(构成网页基础的标记)
和 DOM(用作 API 的文档模型,允许您操作文档的结构和内容)。
It also links to these informative documents:
它还链接到这些信息性文件:
W3C: What is the Document Object Model?
MDN: Introduction - Document Object Model
Wikipedia: Document Object Model
W3C:什么是文档对象模型?
MDN:介绍 - 文档对象模型
维基百科:文档对象模型
Knowing how the DOM developed in a historical context also helps in understanding its structure and how to work with it and this is also covered in the above links.
了解 DOM 在历史背景下是如何发展的也有助于理解其结构以及如何使用它,这也包含在上述链接中。
回答by Golmote Kinoko
I guess the standard is written by the W3C.
我猜这个标准是由 W3C 编写的。
http://www.w3.org/TR/REC-DOM-Level-1/
http://www.w3.org/TR/REC-DOM-Level-1/
You may find also the standards for DOM Level 2 and 3 ;)
您还可以找到 DOM Level 2 和 3 的标准;)
回答by kta
I sometimes use javascriptkitand I find it very useful.
我有时会使用javascriptkit,我发现它非常有用。

