跨标准化浏览器的事件 JavaScript 文档

发布于 2024-10-31 10:46:56 字数 1999 浏览 1 评论 0原文

我正在尝试学习 JavaScript,但发现这个任务在某些方面有点困难。目前我正在研究主要浏览器的事件支持。就事件进展而言,似乎有两种一般风格:(1) 微软方式,以及 (2)标准化方式

我知道 IE 8 不支持 DOM Level 2 事件,但 IE 9 预计支持 DOM Level 3 事件。在 Microsoft 方面,存在一个不同的列表 DHTML事件。还提供了事件对象的说明。

以标准化的方式,我将没有官方规范的 DOM Level 0 支持和 W3C 编写的 DOM Level 2 事件聚集在一起。除MSIE之外的所有主流浏览器,即:Firefox、Chrome、Safari和Opera,普遍都遵循这种标准化方式。每个标准化浏览器都有不同级别的有关事件支持的文档,如以下链接所示。

DOM 0 级事件

Gecko DOM 事件处理程序

Safari HTML 参考:支持的属性

Opera Presto 2.8 中的 HTML、XHTML 和 WML

没有有关 Chrome 的信息。

DOM 2 级事件

W3C DOM 2 级规范

Gecko DOM 事件(似乎不完整)

其他 Gecko DOM 事件

Gecko DOM 事件对象

WebKit 标准支持目标(隐式涵盖了 Chrome 和 Safari 的高水平)

DOM 2 UI、鼠标和Opera Presto 2.8 中的突变事件支持

可以肯定地说标准化浏览器之间的文档是可以互操作的吗?我了解Quirksmode 兼容性表中有关此类信息的信息。然而,当遇到问题时,我很难感到安慰,并希望有一些我可以依靠的细节。此时我还想排除库(例如 Jquery 等)。

I am attempting to learn JavaScript and find this task to be a bit difficult in some respects. Currently I am looking into event support across the major browsers. As far as events go, there seems to be two general flavors: (1) the Microsoft way, and (2) the standardized way.

I am aware that IE 8 does not support DOM Level 2 Events, but that IE 9 is expected to support DOM Level 3 Events. On the Microsoft side there exists a distinct list of DHTML Events. A description of the event object is also available.

In the standardized way I am clumping together DOM Level 0 support which has no official specification, and DOM Level 2 Events that where written by the W3C. This standardized way is generally followed by all of the major browsers except MSIE, namely: Firefox, Chrome, Safari, and Opera. Each of the standardized browsers have a varying level of documentation around their support of events as indicated by the following links.

DOM Level 0 Events

Gecko DOM Event Handlers

Safari HTML Reference: Supported Attributes

HTML, XHTML, and WML in Opera Presto 2.8

No information for Chrome.

DOM Level 2 Events

W3C DOM Level 2 Specification

Gecko DOM Events (appears to be incomplete)

Other Gecko DOM Events

Gecko DOM Event Object

WebKit Standards Support Targets (implicitly covering Chrome and Safari at a high level)

DOM 2 UI, Mouse & Mutation Events support in Opera Presto 2.8

Is it safe to say that the documentation across the standardized browsers is interoperable? I am aware of the Quirksmode Compatibility Tables in regards to this type of information. However, I hardly find that comforting when a problem is encountered and hope that there that are details I can count on instead. I'd also like to exclude libraries (such as Jquery and such) at this point.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苏璃陌 2024-11-07 10:46:56

不。浏览器内的关键事件有很多变化,而像 jQuery 这样的大型库只规范了其中的最低限度(在我看来,正确的是)。处理不一致的唯一方法是向经历过惨痛教训的人学习。我发现的最好的资源是 Jan Wolter 的这个页面: http://unixpapa.com/ js/key.html。准确且比较全面。

No. There is much variation around key events within browsers, and the big libraries such as jQuery only normalize a bare minimum of it (correctly, in my view). The only way to deal with the inconsistencies is to learn from people who have learned the hard way. The best resource by miles that I've found is this page by Jan Wolter: http://unixpapa.com/js/key.html. Accurate and fairly comprehensive.

温柔一刀 2024-11-07 10:46:56

浏览器在检测按键等方面有各种各样的怪癖。并非所有这些错误都是明显的,或者在所有版本的浏览器中都存在。我怀疑是否有一个权威来源可以完美地描述任何一种浏览器的事件,更不用说所有浏览器了。 ppk 非常全面,但他最近将重点转向了移动领域。

无论如何,您可能可以编写一些基本上可以工作的东西,但是这些库的测试量比您自己可能做的要多几个数量级。如果您的目标是学习,那么一定要探索和实验。但不要重新发明轮子。每当我想要针对 DOM 的特定应用程序(例如,在单击事件上按下哪个鼠标按钮)的独立解决方案时,我首先查看文档,然后查看各种库是如何做到这一点的。

Browsers have all sorts of quirks around things like detecting keypresses, etc. Not all of these bugs are obvious, or present in all versions of a browser. I doubt there's a single authoritative source that perfectly describes events even for any one browser, much less all of them. ppk is pretty incredibly comprehensive, but he's shifted his focus to mobile recently.

Anyway, you can probably write something that will mostly work, but these libraries have orders of magnitude more testing than you could possibly do by yourself. If your goal is to learn, then by all means explore and experiment. But don't reinvent the wheel. Whenever I want a standalone solution to a particular application of the DOM (e.g. what mouse button was pressed on a click event) I first look at documentation, and then I look at how the various libraries out there do it.

三月梨花 2024-11-07 10:46:56

大多数人使用 http://www.quirksmode.org/ 作为主要参考

Most people use http://www.quirksmode.org/ as their main reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文