处理事件的顺序" mousedown,mouseup,click" &安培; chrome中超时

时间:2015-01-12 14:11:21

标签: javascript google-chrome events event-loop

在研究了几个关于事件循环,消息队列,javascript堆栈等的页面后,我尝试了以下内容:

<html><head></head>
<body>
<div id="parent">
	<div id="child">
		<span id ="span">
			<p id="innerP">
				Click Me!
			</p>
		</span>
	</div>
</div>
<div id ="text">
</div>

<script>
var innerP = document.getElementById('innerP');
var span = document.getElementById('span');
var child = document.getElementById('child');
var parent = document.getElementById('parent');
var text = document.getElementById('text');

function eventHandler(oEvent){
	var id = oEvent.currentTarget.id;
	var type = oEvent.type;

	text.textContent += oEvent.type + ": " + oEvent.currentTarget.id + ", ";
		setTimeout(function(){
		text.textContent += "CLICK TIMEOUT: "+id+","+type+", ";
	},0);
}

innerP.onclick = eventHandler;
span.onclick = eventHandler;
child.onclick = eventHandler;
parent.onclick = eventHandler;

innerP.onmousedown = eventHandler;
span.onmousedown = eventHandler;
child.onmousedown = eventHandler;
parent.onmousedown = eventHandler;

innerP.onmouseup = eventHandler;
span.onmouseup = eventHandler;
child.onmouseup = eventHandler;
parent.onmouseup = eventHandler;

</script></body></html>

我注意到mousedown事件设置的超时时间将在mousedown块(DOM冒泡)之后立即处理,但是mouseup和click块之后处理mouseup的超时。

假设? chrome是否记住DOM传播路径,以便在主线程中的事件循环的任务/消息队列中更早地处理mouseup和click?

谢谢, 丹尼尔

0 个答案:

没有答案