ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – DOM事件优先级

2019-09-15 23:45:43  阅读:217  来源: 互联网

标签:javascript event-handling javascript-events dom-events eventqueue


JavaScript中处理事件的优先顺序是什么?

以下是按字母顺序排列的事件……

> onabort – 加载图像是
间断
> onblur – 一个元素失去焦点
> onchange – 用户更改
一个领域的内容
> onclick – 鼠标单击一个对象
> ondblclick – 鼠标双击一个
宾语
> one rror – 发生错误时
加载文档或图像
> onfocus – 元素获得焦点
> onkeydown – 键盘键是
压制
> onkeypress – 键盘键是
按下或按下
> onkeyup – 键盘键是
 发布
> onl oad – 页面或图像
 完成装载
> onm ousedown – 鼠标按钮是
 压制
> onm ousemove – 鼠标移动
> onm ouseout – 鼠标移开
 一个元素
> onm ouseover – 鼠标移动
 在元素上
> onm ouseup – 鼠标按钮是
 发布
> onreset – 重置按钮是
 点击
> onresize – 一个窗口或框架
 调整
> onselect – 选择文本
> onsubmit – 提交按钮是
 点击
> onunload – 用户退出页面

他们从事件队列中处理了什么顺序?

优先级不是先进先出(FIFO),所以我相信.

解决方法:

据我所知,这不是过去明确定义的.不同的浏览器可以自由地实现事件排序,但他们认为合适.虽然大多数都足够接近所有实际目的,但是已经并且仍然存在一些奇怪的边缘情况,其中浏览器有所不同(当然,在某些浏览器根本无法发送某些事件的情况下).

也就是说,HTML 5 draft recommendation确实尝试指定事件将如何排队和发送 – the event loop

To coordinate events, user
interaction, scripts, rendering,
networking, and so forth, user agents
must use event loops as described in
this section.

There must be at least one event loop
per user agent, and at most one event
loop per unit of related
similar-origin browsing contexts.

An event loop has one or more task
queues. A task queue is an ordered
list of tasks […]
When a user agent is to queue a task,
it must add the given task to one of
the task queues of the relevant event
loop. All the tasks from one
particular task source must always be
added to the same task queue, but
tasks from different task sources may
be placed in different task queues.
[…]

[…]a user agent could have one task queue
for mouse and key events (the user
interaction task source), and another
for everything else. The user agent
could then give keyboard and mouse
events preference over other tasks
three quarters of the time, keeping
the interface responsive but not
starving other task queues, and never
processing events from any one task
source out of order. […]

注意最后一位:由浏览器实现决定哪些事件将按顺序组合在一起并按顺序处理,以及给予任何特定类型事件的优先级.因此,没有理由期望所有浏览器现在或将来以固定顺序发送所有事件.

标签:javascript,event-handling,javascript-events,dom-events,eventqueue
来源: https://codeday.me/bug/20190915/1806391.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有