简体   繁体   English

javaScript中函数内的evt参数

[英]evt argument inside a function in javaScript

evt argument inside a function in javaScript javaScript中函数内的evt参数

Hello stackoverflow community. 您好stackoverflow社区。 I need to know how is the evt argument used in these functions. 我需要知道在这些函数中如何使用evt参数。 There are some examples in the internet which have the argument evt inside of a function, but I don't see them using the argument. 互联网上有一些在函数内部带有参数evt的示例,但我看不到它们使用该参数。

document.getElementById("creator").addEventListener("click", function(evt){
    alert("created");
});

document.getElementById("change").addEventListener("click", function(evt){
    alert("changed");
});

I guess the evt argument is just set as undefined because those functions are never called with a value for the argument. 我猜evt参数只是设置为undefined,因为这些函数永远不会用参数的值来调用。

  • So what is the reason for setting the argument variable evt? 那么设置参数变量evt的原因是什么呢?
  • can it be hello instead of evt? 可以问好而不是evt吗?
  • if it is predefined to the event listeners, how can I find a list of predefined arguments? 如果已将其预定义为事件侦听器,那么如何找到预定义参数的列表?

When an event is invoked, it will be passed an event object as it's first argument. 调用事件时,会将第一个参数传递给事件对象。 You can name evt whatever you like. 您可以随意命名evt Common names are e evt and event . 俗名是e evtevent

I typically use this for things like 我通常将其用于类似

event.preventDefault() Stop an events default action, on submit for example. event.preventDefault()停止事件默认操作,例如在提交时停止。

and

event.target Find the tagret of the element the event was invoked on. event.target查找在其上调用事件的元素的标记。

There are a lot more properties that can be used on the event object, and becomes very useful if you know how to use it. 事件对象可以使用更多的属性,如果您知道如何使用它,它将变得非常有用。 More information about event object here. 有关事件对象的更多信息,请参见此处。

https://developer.mozilla.org/en/docs/Web/API/Event https://developer.mozilla.org/en/docs/Web/API/Event

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

相关问题 函数(evt)Javascript文件API - function(evt) Javascript File API 在 javascript 中的 function 参数中调用 function 的算法 - Algorithm to call a function inside a function argument in javascript 在 reduce 函数中使用函数参数:Javascript - Use function argument inside reduce function : Javascript 如何通过函数的参数在javascript函数内触发javascript函数? - How to trigger javascript function, inside a javascript function, by function's argument? 该参数应在javascript中作为函数体内执行 - The argument should be executed as a function inside the body in javascript 将参数传递给 Javascript 中 object 内的 function - Passing argument to the function inside the object in Javascript 如何在JavaScript中将参数传递给compose函数中的每个函数 - How to pass an argument to each function inside a compose function in JavaScript 如何将 function 参数传递给 function javascript 内的创建实例? - How to pass a function argument to a created instance inside the function javascript? Javascript“ evt未定义”,但可在Chrome浏览器中使用 - Javascript 'evt is undefined' but works in Chrome 为什么我无法推入数组并在javascript函数参数中使用它? - Why cant I push inside an array and use it in a function argument in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM