JS事件绑定的事件是按照顺序执行的吗

JavaScript05

JS事件绑定的事件是按照顺序执行的吗,第1张

JS绑定的同步事件是按照绑定顺序执行的。W3C对此有相关规范,原文内容如下:

Events which are synchronous (sync events) are treated as if they are in a virtual queue in a first-in-first-out model, ordered by sequence of temporal occurrence with respect to other events, to changes in the DOM, and to user interaction. Each event in this virtual queue is delayed until the previous event has completed its propagation behavior, or been canceled.

简单的翻译一下:

同步事件被看做有一个虚拟的先进先出的队列,按照绑定的时间的顺序进行DOM操作或者用户交互。每一个虚拟队列中的事件都会一直等待直到他前面的那个事件传播(冒泡或捕获)结束或者被取消。

文档地址:https://www.w3.org/TR/DOM-Level-3-Events/#sync-async

事件被触发时,你绑定的函数才被调用,aArr[i].onclick=ck这样写才可以,但ck函数就要修改成:

function

ck(){

var

url=this.getAttribute('href')

window.open(url,"nav","width=400

height=300")

}