[英]evt argument inside a function in javaScript
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,因为这些函数永远不会用参数的值来调用。
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
evt
和event
。
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.