Javascript:运行函数后添加'false' [英] Javascript: adding 'false' after running a function

查看:84
本文介绍了Javascript:运行函数后添加'false'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析一个插件,因为我想修改它。
我看到了像这样的各种事件触发函数:

$ p $ document.getElementById(this.config.form).addEventListener( submit,this._submit,false);

我的问题是 - false 实际上结束了吗?是否与在函数末尾添加 return = false 相同?如果是这样,添加这个的目的是什么?


blockquote>

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


请参阅 MDN


I'm analyzing a plugin as I want to modify it. I see various events firing functions like this:

    document.getElementById(this.config.form).addEventListener("submit", this._submit, false);

My question is - what does false on the end actually do? Is it the same as adding return = false on the end of a function? If so, what is the purpose of adding this?

解决方案

It's useCapture variable.

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.

See MDN.

这篇关于Javascript:运行函数后添加'false'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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