编程语言
首页 > 编程语言> > javascript – DOM事件优先级

javascript – DOM事件优先级

作者:互联网

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