简体   繁体   English

如何在 Javascript 中使用 Chrome.tabs eventListeners

[英]How to use Chrome.tabs eventListeners in Javascript

I'm fairly new to Javascript and I know I should master the basics of it before going anywhere but I would like you to explain me how eventListeners work.我对 Javascript 相当eventListeners ,我知道我应该在去任何地方之前掌握它的基础知识,但我希望你解释一下eventListeners如何工作的。 For example I want to use chrome.tabs.onCreated.addListener(function callback) .例如我想使用chrome.tabs.onCreated.addListener(function callback)

I don't really get what I should put as the callback function.我真的不明白我应该把什么作为回调函数。 I don't know if that's where I put the code that I want to execute when the event happens or not.我不知道这是否是我放置事件发生时要执行的代码的地方。

Syntax.句法。 element.addEventListener(event, function, useCapture); element.addEventListener(event, function, useCapture); The first parameter is the type of the event (like "click" or "mousedown").第一个参数是事件的类型(如“click”或“mousedown”)。 The second parameter is the function we want to call when the event occurs.第二个参数是我们要在事件发生时调用的函数。 The third parameter is a boolean value specifying whether to use event bubbling or event capturing.第三个参数是一个布尔值,指定是使用事件冒泡还是事件捕获。

Well said w3Schools, this is a great resource to help you out. w3Schools 说得好,这是一个很好的资源来帮助你。 https://www.w3schools.com/ Hope this helps https://www.w3schools.com/希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM