<分区>
我试图了解在 Internet Explorer 中添加 addEventListener 时 true
或 false
的作用。根据 Microsoft 的说法,它是 useCapture
。如果我添加一个事件,例如:
element.addEventListener('click', function_name, true);
它似乎没有改变任何东西,监听器仍然有效。谁能解释一下 useCapture
参数的用途?
<分区>
我试图了解在 Internet Explorer 中添加 addEventListener 时 true
或 false
的作用。根据 Microsoft 的说法,它是 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
关于javascript - object.addEventListener 的 useCapture 参数的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13966330/