参见英文答案 > Unable to understand useCapture parameter in addEventListener 9个
我试图了解在Internet Explorer中添加addEventListener时的真或假.据微软称,它是useCapture.如果我添加一个事件,例如:
element.addEventListener('click', function_name, true);
它似乎没有改变任何东西,听众仍然有效.谁能解释一下useCapture参数的用途呢?
解决方法:
它是可选的useCapture参数,它指定为以下事件添加事件处理程序的事件阶段:
Events are handled in two phases: capturing and bubbling. During the
capturing phase, events are dispatched to parent objects before they
are dispatched to event targets that are lower in the object
hierarchy. During the bubbling phase, events are dispatched to target
elements first and then to parent elements. You can register event
handlers for either event phase.
真正
注册捕获阶段的事件处理程序.
假
注册冒泡阶段的事件处理程序.
您可以在此处阅读eventPhase文档:http://msdn.microsoft.com/en-gb/library/ie/ff974944(v=vs.85).aspx
编辑:
请阅读以下内容,其中描述了通过冒泡和捕获定义的事件顺序以及明确的示例. http://www.quirksmode.org/js/events_order.html