js中'function(event)'是什么意思

goJ*_*son 3 javascript events

我不知道“函数(事件)”这句话的意思

Event.add(apple,'click',function(event) {
    Event.stopPropagation(event);
});
Run Code Online (Sandbox Code Playgroud)

参数'event'不是javascript的唯一关键字吗?

关键字可以是某个函数的参数吗?

我理解以下代码的含义:

function(test) {
alert(test);
}
Run Code Online (Sandbox Code Playgroud)

但我不明白这一点:

功能(事件)...

任何人都可以向我解释一下吗?

Nof*_*ood 5

事件对象总是传递给处理程序并包含许多有用的信息。

不同类型的事件提供不同的属性。例如,onclick 事件对象包含:

  • event.target- 对点击元素的引用。IE 使用 event.srcElement 代替。
  • event.clientX/ event.clientY- 单击时指针的坐标。

有关单击了哪个按钮和其他属性的信息。请访问此链接。
它非常简单地回答了您的所有问题

来源http://javascript.info/tutorial/obtaining-event-object

例子:

就像在 HTML 中您分配了这样的事件

<button onclick="alert(event)">See the event</button>
Run Code Online (Sandbox Code Playgroud)

然后

function alert(event) {
    // event.type contains whether this event was invoked in the result of a click etc
    // event.target would contain the reference to the element which invoked this method/event
}
Run Code Online (Sandbox Code Playgroud)