JavaScript DOM API 在哪里记录? [英] Where is the JavaScript DOM API documented?

查看:24
本文介绍了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.

具体来说,我正在使用 new Image() 创建的 HTMLImageElement 上设置一个 onload 回调函数.我还想了解 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 有一些关于各种属性的框架文档:https://developer.mozilla.org/zh/DOM/图像这里没有文档,只有属性列表.onload 属性没有被提及.列出了 src 属性,但没有关于它的文档.

Mozilla has some skeleton documentation of the various attributes here: https://developer.mozilla.org/en/DOM/Image There 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 有更好的文档:http://msdn.microsoft.com/en-us/library/cc197055(VS.85).aspx.

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

我的问题是标准文档在哪里"?Image() 是全局变量,还是全局对象 window 的属性?谁为 windowdocument 编写 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 和一般 XML 文档的基本 DOM 操作可以在 DOM 核心;HTML 文档获得在 DOM HTML 中定义的额外方法.这些是 W3 定义的最新级别"支持;并非所有浏览器都支持 DOM Level 3 Core 中的所有内容.但是 DOM Level 1 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 只是文档对象模型:它指定了您在 document 对象中获得的内容.它不指定其他浏览器功能,例如 window 的内容.浏览器对象模型 (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) 部分.像 window 这样不直接连接到 document 内容的东西.

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' 是全局变量,还是全局对象 'window' 的属性?

Is 'Image' a global variable, or is it a property of 'window' the global object?

Image 由 HTML5 指定为 window 对象的成员,该对象是全局上下文,允许您将其称为 Image...这与作为全局变量完全不是一回事,但对于大多数人来说已经足够了.

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 Level 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').

我还想了解 'src' 属性,因为它具有非标准行为 - 当分配此属性时,图像会重新加载.

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.

好吧,图像不一定会重新加载,但它可能会导致在某些浏览器上触发 load 事件.不幸的是,这不是标准化的(就我所见,即使在 HTML5 中).IE、Firefox 和 Opera 在每个 src 集上触发 load(即使 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 在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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