本文介绍了JavaScript DOM API在哪里记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名C / C ++程序员,我目前正在玩一些Javascript代码,而且在浏览器中可以找到标准Javascript库的文档的问题上遇到问题。

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.

具体来说,我在 HTMLImageElement 中设置了一个 onload 回调函数, code> new Image()。我还想阅读关于 src 属性的属性,因为它具有非标准的行为 - 当该属性被分配到时,图像被重新加载。

Specifically, I am setting an onload callback function on a HTMLImageElement, created with new Image(). 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.

Mozilla在这里提供了各种属性的框架文档:
这里没有文档,只有一个属性列表。没有提到 onload 属性。列出 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 onload property is not mentioned. The src property is listed but there is no documentation on it.

MSDN具有更好的文档:。

MSDN has has better documentation: http://msdn.microsoft.com/en-us/library/cc197055(VS.85).aspx.

我的问题是标准文档在哪里?全局变量是 Image(),还是属于窗口全局对象?谁为窗口文档编写API?有没有标准,或者每个浏览器只是互相复制?

My question is 'where are the standard docs'? Is Image() a global variable, or is it a property of window the global object? Who writes the API for window and document? Is there a standard, or does each browser just copy each other?

推荐答案

DOM实际上是一个单独的JavaScript。 DOM可以从其他语言访问,如IE中的VBScript。而通用的编程语言(如Java,Python,PHP等)都有自己的非基于浏览器的DOM库。

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.

可以在HTML和一般工作的基本DOM操作XML文档可以在中找到; HTML文档在中定义了额外的方法。这些是由W3定义的支持的最新级别不是所有的浏览器都支持DOM Level 3 Core中的所有内容。但很漂亮很可靠。

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 Core is pretty much solid.

令人困惑的是,DOM HTML已经进一步发展,但不在自己的DOM规范中。相反,它是HTML5的一部分。这标准化了许多已经在浏览器中广泛支持的扩展,如 innerHTML ,并添加了一些尚未广泛实现的更多内容(可能会在文件是标准化的。

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只是文档对象模型:它指定了您在文档内获得的内容目的。它没有指定其他浏览器功能,如窗口的内容。浏览器对象模型(BOM)以前是未标准化的; HTML5正在努力正确记录它。

The DOM is only the document object model: it specifies what you get inside the document object. 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.

HTML5还指定了之前未标准化的浏览器对象模型(BOM)的部分。如窗口不直接连接到文档内容的东西。

HTML5 also specifies parts of the browser object model (BOM) that were not previously standardised. Stuff like window that isn't directly connected to the document content.

所有这一切的结果是,没有一个文档可以去,它将告诉你关于你在Web脚本中可用的方法和属性的一切。有些日子,DOM Core和HTML5将覆盖所有这一切,但是今天的HTML5包括很多你不能依靠的,即使是标准文件的标准,也不完全是最可读的指南。所以是的,我恐怕你将不得不继续检查MDC和MSDN的受欢迎支持。

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.

Image 由HTML5指定为窗口对象的成员,作为全局上下文,您可以将其引用为图像 ...这不是一个与全局变量相同的东西,但是对于大多数的变量来说,它是足够接近的。

Image is specified by HTML5 to be a member of the window object, which, being the global context, allows you to refer to it as just Image... that's not quite the same thing as being a global variable, but it's close enough for most.

它是一个构造函数,它返回实现 HTMLImageElement 接口的DOM对象(从DOM 1级HTML扩展为HTML5)。它最初在Netscape 3.0中引入作为预加载图像的机制;加上已创建的图像可以从 document.images 访问,以更改其 src 。今天 new Image()不会对 document.createElement('img')做任何不同的事情。

It is a constructor-function that returns a DOM object implementing the HTMLImageElement interface (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.images to change their src. Today new Image() doesn't do anything different to document.createElement('img').

图像不会重新加载,但可能会导致加载事件在某些浏览器上被触发。不幸的是,这是不规范的(即使在HTML5中,我可以看到)。每个 src set(即使 src 没有改变),而WebKit(Chrome / Safari)只会在初始图像加载时触发它。

Well the image won't be reloaded necessarily, but it may cause the load event 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 load on every src set (even if the src is not changed) whereas WebKit (Chrome/Safari) only ever fires it on the initial image load.

这样的事情是为什么有网站具有不同浏览器行为的大桌子,以及为什么我们仍然需要在不同的浏览器上进行主动测试。

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.

这篇关于JavaScript DOM API在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:24