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

标签 javascript events

我不知道'function(event)'这句话的意思

Event.add(apple,'click',function(event) {
    Event.stopPropagation(event);
});

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

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

我理解以下代码的含义:

function(test) {
alert(test);
}

但是我不明白这个:

function(event)...

有人可以给我解释一下吗?

最佳答案

The event object is always passed to the handler and contains a lot of useful information what has happened.

Different types of events provide different properties. For example, the onclick event object contains:

  • event.target - the reference to clicked element. IE uses event.srcElement instead.
  • event.clientX / event.clientY - coordinates of the pointer at the moment of click.

Information about which button was clicked and other properties. Please visit this link.
It answers all your questions very simply

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

示例:

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

<button onclick="alert(event)">See the event</button>

然后

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
}

关于javascript - js中 'function(event)'是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25594427/

相关文章:

javascript - 搜索后所选项目丢失-Bootstrap table after

javascript - 使用 Javascript 在文本区域中的光标处插入文本

javascript - 在 codeigniter 中单击按钮时更新后端的状态值

javascript - 如何维护套接字事件内连接的每个用户的值(value)

javascript - JS mouseenter 触发了两次

c# - 为什么在 C# 中禁止为发件人发送事件?

multithreading - "Got unknown event 17 ... continuing ..."对于 MPI 意味着什么

javascript - Angular $http.post 谷歌地图Javascript API错误

Javascript 返回值未定义

javascript - 如何使用 jQuery 将事件附加到动态 HTML 元素?