在addEventListener中为false? [英] false in addEventListener?

查看:331
本文介绍了在addEventListener中为false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面这行中:第三个参数保持为false。
这个属性是什么?

  var el = document.getElementById(outside); 
el.addEventListener(click,modifyText,false);


解决方案

这就是 useCapture 参数。来自 文档


useCapture 可选

如果为true,则useCapture表示用户希望启动捕获。在启动捕获之后,指定类型的所有事件将被分派到注册的侦听器,然后被分派到DOM树下的任何EventTarget。向上冒泡树的事件不会触发指定使用捕获的侦听器。有关详细说明,请参阅DOM Level 3事件。如果未指定,则useCapture默认为false。


阅读关于此主题的更多信息 此处

in this below line: third parameter is kept false. what is this attribute??

var el = document.getElementById("outside");
el.addEventListener("click", modifyText, false);

解决方案

That's the useCapture parameter. From documentation

useCapture Optional

If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture. See DOM Level 3 Events for a detailed explanation. If not specified, useCapture defaults to false.

Read more about this topic here.

这篇关于在addEventListener中为false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆